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

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

Within the predicate, just as within an

instruction in XSLT, the context item is the item from the sequence that's being tested; the context position is the position of that item in the sequence being filtered (counting from one); and the context size is the number of items in the sequence. This means, for example, that you can select the first half of the sequence by writing:

$sequence[position() * 2 <= last()]

There is a special rule for predicates, namely that if the value of the predicate is a number
N
, then it is treated as a shorthand for the condition
[position()=
N
]
, which selects the
N
th item in the sequence.

For path expressions of the form
A/B
, the rules are the same as the rules for predicates. The expres sion B is evaluated once for each node in the sequence produced by evaluating A, and while B is being evaluated, that node is the context item, the position of that node in the sequence is the context position, and the number of items in the sequence is the context size. However, it's very hard to construct a useful path expression that actually uses
position()
or
last()
on the right-hand side of the
/
operator. Using them inside a predicate such as
A/B[last()]
doesn't count, of course, because the focus changes again once you're inside the predicate.

It's also important to be aware that certain expressions
don't
change the focus. Specifically, the focus is not changed within a
for
,
some
, or
every
expression (these expressions are described in Chapter 10). So the expression:

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

Other books

Thin Space by Jody Casella
What She'd Do for Love by Cindi Myers
Gathering of the Chosen by Timothy L. Cerepaka
On the Loose by Tara Janzen
Guarding Sophie by Julie Brannagh
Apocalypse Soldier by William Massa
Birthright by Nora Roberts
A Sounding Brass by Shelley Bates
Crane by Rourke, Stacey