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

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

XSLT also initializes the context position and size when a sequence of nodes is processed using

.

In other host languages, for example, in APIs for invoking XPath, it's quite common that there is no provision for setting the context position and size, only the context item. There is no obligation on the host language to provide this capability. It can choose always to set the context position and size to one, or to leave them undefined (in which case it's an error to use the functions
position()
or
last()
).

The context item will very often be a node, but in principle it can be any kind of item, that is, a node or an atomic value. In XSLT 2.0, for example, you can use the

instruction to process a sequence of strings, and within such an instruction the context item will be a string. If you then use a path expression that relies on the context item being a node (for example, a path expression such as
@code
), it will fail with an error.

The focus is initialized by the host language on entry to an XPath expression, but the focus can change when evaluating a subexpression. There are two constructs in XPath that change the focus: the path expression
A/B
, and the filter expression
S[P]
. Path expressions are described in full detail in Chapter 9 of this book, and filter expressions in Chapter 10. Let's take the filter expressions first.

In fact there are two very similar constructs of the form S[P] that use predicates in square brackets, and we'll explain the difference between them in Chapters 9 and 10. For the purpose of this discussion, there is no distinction—they both handle the focus in the same way.

In this construct,
S
is a sequence (that is, it's some expression whose value is a sequence—and as every expression evaluates to a sequence, this actually means it can be any expression whatsoever).
P
is a predicate, which filters the sequence by selecting only those items that match a given condition. So if we write
author[@surname=“Smith”]
we are selecting those

elements that have a
surname
attribute whose value is
Smith
.

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

Other books

Burning Justice by Leighann Dobbs
Circle the Soul Softly by Davida Wills Hurwin
Melabeth the Vampire by Hood, E.B.
Lady Meets Her Match by Gina Conkle
The Stones of Ravenglass by Nimmo, Jenny
The Pause by John Larkin
Dark Matter by Blake Crouch