Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Don't make the mistake of thinking that if
$n
holds the string
“title”
, say, then./$n
means the same as
./title
. Variables in XPath represent values, not parts of an expression. To select the child elements whose name is in
$n
, use*[name()=$n]
.
Examples of the Binary/
Operator
The following examples illustrate that although axis steps are often used as operands of/
, any kind of expression is legal:
Expression | Description |
descendant::para/@style | In this example both operands are axis steps. The first step selects the descendants of the context node that are![]() ![]() ![]() ![]() style attributes of these elements. |
section[1]/clause[3] | In this example each of the operands includes a positional predicate. The first step selects the first Step selects the third |
chapter/section/para/sentence | This path expression selects every![]() ![]() ![]() ![]() |
doc(‘a.xml’)/id(‘Z123’) | This example illustrates that the operands of the![]() ![]() AxisStep expressions. This example selects the document with a particular relative URI, and using the resulting document node as the context node, then selects the element with a particular ID value. |
book/(chapter|appendix) | This is another example that uses an operand that is not an AxisStep . For each selected ![]() ![]() |
$chap/title | Using a variable reference on the left-hand side of![]() ![]() ![]() ![]() ![]() ![]() |