XPATH Axes and their Shortcuts.

We have now learned the basics of selecting content in reference to the current page, and know the very basics of how it is used.  Now we can cover a few additional commands, and explain how they work.

XPATH works on the premise of Axes, which is how the data relates to the current node.  There are several Axis listed below with graphic depictions of the results.  Please note the numbers, as those are the order in which the results would be returned.

Self Axis

While it is rarely used, the self axis actually returns the node in reference.

$currentPage/self::node

AxisName-self

Child Axis

We mentioned the child axis earlier, and actually used its shortcut right off.  The child axis select the nodes immediately below the node in reference.  While the verbose method is rarely used, it is here for reference.

$currentPage/child::node

$currentPage/node

AxisName-child 

Parent Axis

The parent axis allows us to see the node immediately above the node in reference.

$currentPage/parent::node

$currentPage/../

AxisName-parent 

Descendant Axis

Next we have descendant.  The descendant axis retrieves all nodes below the node in reference no matter the depth.

$currentPage/descendant::node

$currentPage//node

AxisName-descendant

Descendant-or-self Axis

The descendant-or-self axis returns all nodes below the current node, but also returns the node in reference to the command.

$currentPage/descendant-or-self::node

AxisName-descendant-or-self

Ancestor Axis

The ancestor axis selects all nodes that are ancestors, or the parent, and the parent's parent, and so on, to the node in reference.

$currentPage/ancestor::node

AxisName-ancestor

Ancestor-or-self Axis

The ancestor-or-self axis selects all nodes that are ancestors, or the parent, and the parent's parent, and so on, including the node in reference.

$currentPage/ancestor-or-self::node

AxisName-ancestor-or-self

Preceding Axis

Coming soon

AxisName-preceding

Preceding-sibling Axis

Coming soon

AxisName-preceding-sibling

Following Axis

Coming soon

AxisName-following

Following-sibling Axis

Coming Soon

AxisName-following-sibling