Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
A numeric predicate
[P]
is simply a shorthand for the boolean predicate
[position() = P]
, so you could also achieve the required effect by writing
[position() = @sequence-number]
.
Note that the rules for recognizing a predicate as a number are very strict. For example, a string written as
“20”
is not considered to be a number: it's the type label on the value that matters, not the format of the value itself. Equally, the XSLT variable declared in the example below is not a number, it is the document node at the root of a temporary tree (see the
If you want to use this value as a predicate, either write it so the value of the variable is a number:
(but don't write
select = “‘3’”
, because that would make it a string) or force it to a number in the predicate. Any of the following will work:
As explained in Chapter 7, every expression is evaluated with a particular focus. The focus for evaluating the predicate is not the same as the focus for the expression that it forms part of. The predicate is applied separately to each node selected by the axis, and each time it is evaluated:
As we saw earlier the number assigned to a node selected by an
AxisStep
depends on the direction of the axis used in that
AxisStep
. Some axes (child, descendant, descendant-or-self, following, following-sibling) are forward axes, so the
position()
function numbers the nodes in document order. Other axes (ancestor, ancestor-or-self, preceding, preceding-sibling) are reverse axes, so
position()
numbers them in reverse document order. The self and parent axes return a single node, so the order is irrelevant. The ordering of nodes on the attribute and namespace axes is undefined, so positional predicates on these axes don't make much sense, though they are permitted.