Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The directions of navigation through the tree are called
axes
. The various axes are defined in detail in Chapter 9. They include the following:
As well as specifying the direction of navigation through the tree, each step in a path expression can also qualify which nodes are to be selected. This can be done in several different ways:
The syntax of a path expression uses
/
as an operator to separate the successive steps. A
/
at the start of a path expression indicates that the origin is the document node; otherwise, it is generally the context node (we'll be looking at the notion of context in the next section). Within each step, the axis is written first, separated from the other conditions by the separator
::
. However, the child axis is the default, so it may be omitted; and the attribute axis may be abbreviated to
@
.
For example:
child::item/attribute::category
is a path expression of two steps; the first selects all the child
category
attributes. This can be abbreviated to:
item/@category
Predicates that the nodes must satisfy are written in square brackets, for example:
item[@code=‘T’]/@category
This selects the
category
attributes of those child
code
attribute whose value is
T
.
There are many ways of abbreviating path expressions to make them easier to write, but the basic structure remains the same. The full detail appears in Chapter 9.
Context
The way in which XPath expressions are evaluated is to some extent context dependent. For example, the value of the expression
$x
depends on the current value of the variable
x
, and the value of the expression
.
depends on which node is currently being processed in the source document.