Axes

An axis is an optional part of an axis step that specifies a direction of movement through an XML document.

Table 1 describes the axes that are supported in DB2® XPath.

Table 1. Supported axes in DB2 XPath
Axis Description Notes
child Returns the children of the context node. This axis is the default. Document nodes and element nodes are the only nodes that have children. If the context node is any other kind of node, or if the context node is an empty document or element node, then the child axis is an empty sequence. The children of a document node or element node may be element, processing instruction, comment, or text nodes. Attribute and document nodes can never appear as children.
descendant Returns the descendants of the context node (the children, the children of the children, and so on).  
attribute Returns the attributes of the context node. This axis is empty if the context node is not an element node.
self Returns the context node only.  
descendant-or-self Returns the context node and the descendants of the context node.  
parent Returns the parent of the context node, or an empty sequence if the context node has no parent. An element node can be the parent of an attribute node even though an attribute node is never a child of an element node.

DB2 XPath does not support the additional axes defined by the full axis feature of the W3 standard.

An axis can be either a forward or reverse axis. A forward axis contains the context node and nodes that are after the context node in document order. A reverse axis contains the context node and nodes that are before the context node in document order. In DB2 XPath, the forward axes include: child, descendant, attribute, self, and descendant-or-self. The only supported reverse axis is the parent axis.

When an axis step selects a sequence of nodes, each node is assigned a context position that corresponds to its position in the sequence. If the axis is a forward axis, context positions are assigned to the nodes in document order, starting with 1. If the axis is a reverse axis, context positions are assigned to the nodes in reverse document order, starting with 1.