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 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, the step selects any attributes that match the name test. Otherwise, on all other axes, the step selects any elements that match the name test. For the QNames to match, the expanded QName of the node must be 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).
Table 1 describes the name tests that are supported in 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 that are equal to the specified QName. On all other axes, this test matches element nodes that are equal to the specified QName. | 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 elements on the child axis. |
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. Table 2 describes the kind tests that are supported in 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(NCName) | Matches any processing-instruction node (on the specified axis) whose name (called its "PITarget" in XML) matches the NCName that is specified in this name test. | In the expression child::processing-instruction(
xml-stylesheet) , the kind test processing-instruction(
xml-stylesheet) selects any processing instruction nodes
on the child axis whose PITarget is xml-stylesheet. |
processing-instruction(StringLiteral) | Matches any processing-instruction
node (on the specified axis) whose name matches the string literal
that is specified in this test. This node test provides backwards compatibility with XQuery 1.0. |
In the expression child::processing-instruction("xml-stylesheet") ,
the kind test processing-instruction("xml-stylesheet") selects
any processing instruction nodes on the child axis whose PITarget
is xml-stylesheet. |
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. |
element(QName) | Matches any element node (on the specified axis) whose name matches the qualified name that is specified in this test. | In the expression child::element("price") ,
the kind test element("price") selects
any element nodes on the child axis whose name is price. |
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. |
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. |
attribute(QName) | Matches any attribute node (on the specified axis) whose name matches the qualified name that is specified in this test. | In the expression child::attribute("price") ,
the kind test attribute("price") selects
any attribute nodes on the child axis whose name is price. |
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. |
document-node() | Matches any document node on the specified axis. | In the expression child::document-node() ,
the kind test document-node() selects any document
nodes on the child axis. |
document-node(element(QName)) | Matches any document node on the specified axis that has only one element node (on the specified axis), and the name of the node matches the qualified name that is specified in this test. | In the expression child::document-node(element("price")) ,
the kind test document-node(element("price")) selects
any document nodes on the child axis that have a single element whose
name is price. |
document-node(element(*)) | Matches any document node on the specified axis that has element nodes. | In the expression child::document-node(element(*)) ,
the kind test document-node(element(*)) selects any
document nodes on the child axis that have element nodes. |