Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
There are two very similar constructs in XPath that use predicates. They can be used in an
AxisStep
, to qualify the nodes selected by the axis, and they can be used in a
FilterExpr
, to filter any sequence. We will talk about the more general filter expressions in Chapter 10 and concentrate here on the use of predicates with an
AxisStep
. The meaning of the two cases is very similar, and it's easy to use them without always being aware of the difference.
For example:
Expression | Description |
para[position() > 1] | Here the predicate![]() ![]() AxisStep ![]() ![]() ![]() ![]() AxisStep , the results are guaranteed to be in document order and to contain no duplicates. |
$para[position() > 1] | Here the predicate![]() ![]() ![]() ![]() |
In both cases the effect of a predicate is to select a subset of the items in a sequence. There's a significant difference when a predicate is used with a path expression of more than one step. For example:
Expression | Description |
chapter/para[1] | Here the predicate![]() ![]() Step ![]() ![]() ![]() ![]() |
(chapter/para)[1] | This is a FilterStep where the predicate ![]() ![]() ![]() ![]() |