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

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

that are


elements.

The second predicate is now applied to each node in this sequence of


elements. In each case the predicate
[last()]
returns the same value: a number indicating how many


elements there are in the sequence. As this is a numeric predicate, a node passes the test when
[position() = last()]
, that is, when the position of the node in the sequence (taken in its original order) is equal to the number of nodes in the sequence. So the meaning of
$headings[self::h1][last()]
is “the last


element in the sequence
$headings
.”

Note that this isn't the same as
$headings[last()][self::h1]
, which means “the last item in
$headings
, provided that it is an


element.”

The operation of a
Predicate
in a
FilterExpr
is very similar to the application of a
Predicate
in an
AxisStep
(which we studied in Chapter 9, on page 618), and although they are not directly related in the XPath grammar rules, you can often use predicates without being fully aware of which of these two constructs you are using. For example,
$para[1]
is a
FilterExpr
, while
para[1]
is an
AxisStep
. The main differences to watch out for are, firstly, that in a path expression the predicates apply only to the most recent
Step
(for example, in
book/author[1]
the
[1]
means the first author within each book), and secondly, that in a filter expression the items are always considered in the order of the supplied sequence, whereas in an
AxisStep
they can be in forward or reverse document order, depending on the direction of the axis.

Other books

Flowering Judas by Jane Haddam
Lost in Tennessee by DeVito, Anita
Disappeared by Anthony Quinn
The Great Husband Hunt by Laurie Graham
The Silver Thread by Emigh Cannaday
The Cooked Seed by Anchee Min