assign command


assign $id=xpath


assign %id=xpath



In the first two cases (where dollar sign appears) store the result of evaluation of the xpath in a variable named $id. In this case, xpath is evaluated in a simmilar way as in the case of the count: if it results in a literal value this value is used. If it results in a node-list, number of nodes occuring in that node-list is used. Use the string() XPath function to obtain a literal values in these cases.

Example 1. String expressions

xsh> $a=string(chapter/title)
xsh> $b="hallo world"

Example 2. Arithmetic expressions

xsh> $a=5*100
xsh> $a
xsh> $a=(($a+5) div 10)
xsh> $a

Example 3. Counting nodes

xsh> $a=//chapter
xsh> $a
xsh> %chapters=//chapter
xsh> $a=%chapters
xsh> $a

Example 4. Some caveats of counting node-lists

xsh> ls ./creature
<creature race='hobbit' name="Bilbo"/>

## WRONG (@name results in a singleton node-list) !!!
xsh> $name=@name
xsh> $name

## CORRECT (use string() function)
xsh> $name=string(@name)
xsh> $name

In the other two cases (where percent sign appears) find all nodes matching a given xpath and store the resulting node-list in the variable named %id. The variable may be later used instead of an XPath expression.

See Also