assign

Usage

assign $id=xpath

$id=xpath

assign %id=xpath

%id=xpath

Description

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 9. String expressions

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

Example 10. Arithmetic expressions

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

Example 11. Counting nodes

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

Example 12. 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
$name=1

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

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

variables