XPath Axes


XML Example Document

We will use this XML document in the examples below:

<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book> <title lang="en">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="en">Learning XML</title> <price>39.95</price> </book> </bookstore>


XPath Axes

Axes can define a node set relative to the current node.

Axis Name Result
ancestor Selects all ancestors (parent, grandfather, etc.) of the current node.
ancestor-or-self Selects all ancestors (parent, grandfather, etc.) of the current node and the current node itself.
attribute Selects all attributes of the current node.
child Selects all child elements of the current node.
descendant Selects all descendant elements (children, grandchildren, etc.) of the current node.
descendant-or-self Selects all descendant elements (children, grandchildren, etc.) of the current node and the current node itself.
following Selects all nodes after the closing tag of the current node in the document.
following-sibling Selects all sibling nodes after the current node.
namespace Selects all namespace nodes of the current node.
parent Selects the parent of the current node.
preceding Selects all nodes before the start tag of the current node in the document.
preceding-sibling Selects all sibling nodes before the current node.
self Selects the current node.
Other Extensions