Previous: XPath vocabulary and syntax - XPath - Next: XPath functions


Please refer to http://www.w3.org/TR/xpath#axes, section 2.2 of the XPath specification for complete information about axes.

XPath uses the term axis to describe where an XPath expression should be evaluated. The following axis's are available:

child
Child is the default axis. It contains all of the children of the context node, but only one level of children. Referring to the zoo XML document (in XPath), if the context node is zoo, then the child axis contains animals and people. The child axis is the default; if the axis is left off the location step, the child axis is assumed.
descendant
This axis contains all of the children of the context, and all of the children of the children, for as many levels as there are. Referring to the zoo XML document (in the XPath node), if the context node is zoo, then the child axis contains animals, people, and all of the dog, cat, and person nodes.
parent
The parent axis contains the parent node of the context node if one exists (the root node doesn't have a parent). If the context node is animals, then the parent would be zoo.
ancestor
The ancestor axis contains the parent of the context node and the parent's parent and so on.
following-sibling
The following-sibling axis contains all the following siblings of the context node; if the context node is an attribute node or namespace node, the following-sibling axis is empty.
preceding-sibling
The preceding-sibling axis contains all the preceding siblings of the context node; if the context node is an attribute node or namespace node, the preceding-sibling axis is empty.
following
The following axis contains all of the nodes coming after the context node in the document, excluding any descendants, namespace, or attribute nodes.
preceding
The preceding axis contains all of the nodes coming before the context node in the document, excluding any ancestors, namespace, or attribute nodes.
attribute
The attribute axis contains all of the attributes of the context node; this axis will be empty if the context node is not an element. From the zoo example (in the XPath node), if the context node was the first person element, the attribute axis would contain name and job. The attribute axis can be abbreviated as "@" (e.g. use "@job" instead of "attribute::job")
namespace
The namespace axis contains the namespace nodes of the context node; this axis will be empty if the context node is not an element.
self
This axis contains only the context node. The self axis together with a node test of "node()" can be abbreviated as ".".
descendant-or-self
This axis contains the context node and all of it's descendants. It can be abbreviated as "//".
ancestor-or-self
This axis contains the context node and all of it's ancestors.