Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Examples
Expression | Description |
$paragraphs[23] | Selects the 23rd item in the sequence that is the value of variable $paragraphs , taking them in the order of that sequence. If there is no 23rd item, the expression returns an empty sequence. |
key(‘empname’, ‘John Smith’)[@loc = ‘Sydney’] | Assuming that the key![]() ![]() John Smith who are located in Sydney. The key() function is available only in XSLT. |
(//section|//subsection) [title = ‘Introduction’] | Selects all![]() ![]() |
(//@href/doc(.)) [pricelist][1] | This first selects all documents referenced by URLs contained in href attributes anywhere in the source document, by applying the doc() function to the value of each of these attributes. The ![]() ![]() |
Where a predicate is used as part of a
FilterExpr
(as distinct from an
AxisStep
), the items are considered in their original sequence for the purpose of evaluating the
position()
function within the predicate. There are some cases where the order of the sequence is not predictable, but it is still possible to use positional predicates. For example, the result of the
distinct-values()
function is in an undefined order, but you can still writedistinct-values($in)[1]
to obtain one item in the sequence, chosen arbitrarily.
Thefor
Expression
Thefor
expression is one of the most powerful new features in XPath 2.0 and is closely related to the extension to the data model to handle sequences. Its effect is to apply an expression to every item in an input sequence and to return the concatenated results of these expressions.