Node tests

A node test is a condition that must be true for each node that is selected by an axis step. The node test can be expressed as either a name test or a kind test. A name test selects nodes based on the name of the node. A kind test selects nodes based on the kind of node.

Name tests

A name test consists of a QName or a wildcard. When a name test is specified in an axis step, the step selects the nodes on the specified axis that match the QName or wildcard. If the name test is specified on the attribute axis, then the step selects any attributes that match the name test. On all other axes, the step selects any elements that match the name test. The QNames match if the expanded QName of the node is equal (on a codepoint basis) to the expanded QName that is specified in the name test. Two expanded QNames are equal if their namespace URIs are equal and their local names are equal (even if their namespace prefixes are not equal).

Important: Any prefix that is specified in a name test must correspond to one of the statically known namespaces for the expression. For name tests that are performed on the attribute axis, unprefixed QNames have no namespace URI. For name tests that are performed on all other axes, unprefixed QNames have the namespace URI of the default element/type namespace.

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

Table 1. Supported name tests in Db2 XQuery
Test Description Examples
QName Matches any nodes (on the specified axis) whose QName is equal to the specified QName. If the axis is an attribute axis, this test matches attribute nodes. On all other axes, this test matches element nodes. In the expression child::para, the name test para selects all of the para elements on the child axis.
* Matches all nodes on the specified axis. If the axis is an attribute axis, this test matches all attribute nodes. On all other axes, this test matches all element nodes. In the expression, child::*, the name test * matches all of the elements on the child axis.
NCName:* Specifies an NCName that represents the prefix part of a QName. This name test matches all nodes (on the specified axis) whose namespace URI matches the namespace URI to which the prefix is bound. If the axis is an attribute axis, this test matches attribute nodes. On all other axes, this test matches element nodes. In the expression child::ns1:*, the name test ns1:* matches all of the elements on the child axis that are associated with the namespace that is bound to the prefix ns1.
*:NCName Specifies an NCName that represents the local part of a QName. This name test matches any nodes (on the specified axis) whose local name is equal to the NCName. If the axis is an attribute axis, this test matches attribute nodes. On all other axes, this test matches element nodes. In the expression child::*:customerinfo, the name test *:customerinfo matches all of the elements on the child axis that have the local name customerinfo, regardless of the namespace that is associated with the element name.

Kind tests

When a kind test is specified in an axis step, the step selects only those nodes on the specified axis that match the kind test. The following table describes the kind tests that are supported inDb2 XQuery.

Table 2. Supported kind tests in Db2 XQuery
Test Description Examples
node() Matches any node on the specified axis. In the expression child::node(), the kind test node() selects any nodes on the child axis.
text() Matches any text node on the specified axis. In the expression child::text(), the kind test text() selects any text nodes on the child axis.
comment() Matches any comment node on the specified axis. In the expression child::comment(), the kind test comment() selects any comment nodes on the child axis.
processing-instruction() Matches any processing-instruction node on the specified axis. In the expression child::processing-instruction(), the kind test processing-instruction() selects any processing instruction nodes on the child axis.
element() or element(*) Matches any element node on the specified axis. In the expression child::element(), the kind test element() selects any element nodes on the child axis. In the expression child::element(*), the kind test element(*) selects any element nodes on the child axis.
attribute() or attribute(*) Matches any attribute node on the specified axis. In the expression child::attribute(), the kind test attribute() selects any attribute nodes on the child axis. In the expression child::attribute(*), the kind test attribute(*) selects any attribute nodes on the child axis.
document-node() Matches any document node on the specified axis. In the expression self::document-node(), the kind test document-node() selects a document node that is the context node.