Axes
A location path uses an axis to specify the relationship between the nodes selected by the location step and the context node.
Axes | Description |
---|---|
|
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 |
|
The context node and its ancestors. The |
|
The attributes of the context node. This axis will be empty unless the context node is an element. |
|
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. |
|
The descendants of the context node. A descendant is a child or a child of a child and so on; thus the |
|
The context node and its descendants. |
|
All nodes that are after the context node in the tree, excluding any descendants, attribute nodes, and namespace nodes. |
|
All the following siblings of the context node. The If the context node is an attribute node or namespace node, the |
|
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. |
|
The parent of the context node, if there is one. The parent is the node immediately above the context node in the tree. |
|
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. |
|
All the preceding siblings of the context node. The If the context node is an attribute node or namespace node, the |
|
Just the context node itself. |
Remarks
namespace
Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element (including thexml
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:For every attribute on the element whose name starts with
xmlns:
.For every attribute on an ancestor element whose name starts with
xmlns:
— unless the element itself or a nearer ancestor redeclares the prefix.For an
xmlns
attribute, if the element or some ancestor has anxmlns
attribute, and the value of thexmlns
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: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 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.
Examples
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 |
---|---|
|
|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|