Location Steps
A version of this page is also available for
4/8/2010
A location step selects a set of nodes relative to the context node. It is composed of three parts.
- Axis
Specifies the tree relationship between the nodes selected by the location step and the context node.
- Node test
Specifies the node type and expanded-name of the nodes selected by the location step.
- Zero or more predicates
Use expressions to further refine the set of nodes selected by the location step.
The syntax for a location step is the axis name and node test separated by a double colon, followed by zero or more expressions, each in square brackets.
For example, in the following, child
is the name of the axis, para
is the node test, and [position()=1]
is a predicate.
child::para[position()=1]
The node-set selected by the location step is the node-set that results from generating an initial node-set from the axis and node test, and then filtering that node-set by each of the predicates in turn.
The initial node-set consists of the nodes having the relationship to the context node specified by the axis and having the node type and expanded-name specified by the node test. For example, a location step descendant::para
selects the para
element descendants of the context node: descendant specifies that each node in the initial node-set must be a descendant of the context; para specifies that each node in the initial node-set must be an element named "para". The available axes are described in Axes. The available node tests are described in Node Tests. The meaning of some node tests is dependent on the axis.
The initial node-set is filtered by the first predicate to generate a new node-set; this new node-set is then filtered using the second predicate, and so on. The final node-set is the node-set selected by the location step. The axis affects how the expression in each predicate is evaluated, so the semantics of a predicate is defined with respect to an axis.