Axes

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

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.

The following table describes the axes that are supported in Db2 XQuery.

Table 1. Supported axes in Db2 XQuery
Axis Description Direction Comments
child Returns the children of the context node. Forward 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 a document or element node without any children, the child axis is an empty sequence. The children of a document node or element node can 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). Forward  
attribute Returns the attributes of the context node. Forward This axis is empty if the context node is not an element node.
self Returns the context node only. Forward  
descendant-
or-
self
Returns the context node and the descendants of the context node. Forward  
parent Returns the parent of the context node, or an empty sequence if the context node has no parent. Reverse An element node can be the parent of an attribute node even though an attribute node is never a child of an element node.

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. Context position assignments allow you to select a node from the sequence by specifying its position.