XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (406 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.67Mb size Format: txt, pdf, ePub
ads

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

topic in Chapter 6):

3

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:

  • The context item (the item selected by
    .
    ) is the node to which the predicate is being applied.
  • The context position (the result of the
    position()
    function) is the number assigned to that node within the sequence of nodes.
  • The context size (the result of the
    last()
    function) is the number of nodes in the sequence.

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.

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.67Mb size Format: txt, pdf, ePub
ads

Other books

The Mushroom Man by Stuart Pawson
Yesterday's Echo by Matt Coyle
Clown in the Moonlight by Piccirilli, Tom
The Prophet of Yonwood by Jeanne Duprau
Here Comes Trouble by Delaney Diamond
Planet Predators by Saxon Andrew
Garden of the Moon by Elizabeth Sinclair
Son of Fortune by Victoria McKernan