A location path uses an axis to specify the relationship between the nodes selected by the location step and the context node.
Axes | Description |
---|---|
ancestor:: |
The ancestors of the context node.
The ancestors of the context node consist of the parent of the context node and the parent's parent and so on; thus the |
ancestor-or-self:: |
The context node and its ancestors.
The |
attribute:: |
The attributes of the context node.
This axis will be empty unless the context node is an element. |
child:: |
The children of the context node.
A child is any node immediately below the context node in the tree. However, neither attribute or namespace nodes are considered children of the context node. |
descendant:: |
The descendants of the context node.
A descendant is a child or a child of a child and so on; thus the |
descendant-or-self:: |
The context node and its descendants. |
following:: |
All nodes that are after the context node in the tree, excluding any descendants, attribute nodes, and namespace nodes. |
following-sibling:: |
All the following siblings of the context node.
The If the context node is an attribute node or namespace node, the |
namespace:: |
The namespace nodes of the context node.
There is a namespace node for every namespace which is in scope for the context node. This axis will be empty unless the context node is an element. |
parent:: |
The parent of the context node, if there is one.
The parent is the node immediately above the context node in the tree. |
preceding:: |
All nodes that are before the context node in the tree, excluding any ancestors, attribute nodes, and namespace nodes.
One way to think of the preceding axis is all nodes whose content occurs in their entirety before the start of the context node. |
preceding-sibling:: |
All the preceding siblings of the context node.
The If the context node is an attribute node or namespace node, the |
self:: |
Just the context node itself. |
Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element (including the xml
prefix, which is implicitly declared by the XML Namespaces Recommendation) and one for the default namespace if one is in scope for the element. The element is the parent of each of these namespace nodes; however, a namespace node is not a child of its parent element. Elements never share namespace nodes: if one element node is not the same node as another element node, then none of the namespace nodes of the one element node will be the same node as the namespace nodes of another element node. This means that an element will have a namespace node:
xmlns:
.xmlns:
unless the element itself or a nearer ancestor redeclares the prefix.xmlns
attribute, if the element or some ancestor has an xmlns
attribute, and the value of the xmlns
attribute for the nearest such element is non-empty.The <sample>
element in the following instance:
<A xmlns="urn:A"> <B xmlns:test="sample"> <sample xmlns:sampletest="sampletest"/> </B> </A>
contains the following namespace nodes:
xmlns="urn:A" xmlns:test="sample" xmlns:sampletest="sampletest"
The <sample>
element in the following instance:
<A xmlns="urn:A"> <B xmlns="" xmlns:test="sample"> <sample xmlns:sampletest="sampletest" xmlns:bar="test"/> </B> </A>
contains the following namespace nodes:
xmlns:sampletest="sampletest" xmlns:test="test"
Note An attribute xmlns=""
undeclares the default namespace.
A namespace node has an expanded-name: the local part is the namespace prefix (this is empty if the namespace node is for the default namespace); the namespace Uniform Resource Identifier (URI) is always null.
The string-value of a namespace node is the namespace URI that is being bound to the namespace prefix; if it is relative, it must be resolved just like a namespace URI in an expanded-name.
following::
The examples for the following::
axis refer to this instance document:
<A> <B> <C>sample</C> <C>sample2</C> </B> <B> <C>sample</C> <C>sample2</C> <D>sample3</D> </B> </A>
Query | Returned nodes |
---|---|
A/B[1]/following::* |
<B><C>sample</C> <C>sample2</C> <D>sample3</D> </B> <C>sample</C> <C>sample2</C> <D>sample3</D> |
A/B[1]/following::node() |
<B><C>sample</C> <C>sample2</C> <D>sample3</D> </B> <C>sample</C> sample <C>sample2</C> sample2 <D>sample3</D> sample3 |
preceding::
The example for the preceding::
axis refer to this instance document:
<A> <B> <C test="sampletest">sample</C> <C>sample2</C> </B> <B> <C>sample</C> <C>sample2</C> <D>sample3</D> </B> </A>
Query | Returned nodes |
---|---|
A/B[2]/preceding::* |
<B><C test="sampletest">sample</C> <C>sample2</C> </B> <C>sample</C> <C>sample2</C> |
following-sibling::
The example for the following-sibling::
axis refers to this instance document:
<A> <B> <C test="sampletest">sample</C> <C>sample2</C> </B> <B> <C>sample</C> <C>sample2</C> <D>sample3</D> </B> </A>
Query | Returned nodes |
---|---|
A/B[1]/following-sibling::* |
<B><C>sample</C> <C>sample2</C> <D>sample3</D> |
preceding-sibling::
The example for the preceding-sibling::
axis refers to this instance document:
<A> <B> <C test="sampletest">sample</C> <C>sample2</C> </B> <B> <C>sample</C> <C>sample2</C> <D>sample3</D> </B> </A>
Query | Returned nodes |
---|---|
A/B[2]/preceding-sibling::* |
<B><C test="sampletest">sample</C> <C>sample2</C> |
Location Steps | Node Tests | Predicates