Home » XPath Axes

XPath Axes

As we know that path defines the location of a node using absolute or relative path. In the same manner XPath axes are used to identify elements by their relationship like parent, child, sibling, etc. Axes refer to axis on which elements are lying relative to an element.

A list of various Axis values:

1)ancestorIt specifies the ancestors of the current nodes which include the parents up to the root node.
2)ancestor-or-selfIt specifies the current node and its ancestors.
3)attributeIt specifies the attributes of the current node.
4)childIt specifies the children of the current node.
5)descendantIt specifies the descendants of the current node i.e. the node’s children up to the leaf node(no more children).
6)descendant-or-selfIt specifies the current node and it’s descendants.
7)followingIt specifies all nodes that come after the current node.
8)following-siblingIt specifies the following siblings of the context node. Siblings are at the same level as the current node and share it’s parent.
9)namespaceIt specifies the namespace of the current node.
10)parentIt specifies the parent of the current node.
11)precedingIt specifies all nodes that come before the current node (i.e. before it’s opening tag).
12)selfIt specifies the current node.

XPath Axes Example

Here the firstname is related to employee node of the XML document named employee.xml

Let’s create an XML document named “employee.xml” and its stylesheet document named “employee.xsl” which uses the XPath expression.




Xpath Axes 1

Next TopicXPath Operators

You may also like