Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Node Tests
An axis step always includes a node test. This tests whether a node satisfies specified constraints on the kind of node or the name of the node.
Expression | Syntax |
NodeTest | NameTest | KindTest |
A
NodeTest
is either a
NameTest
or a
KindTest
. A
NameTest
selects nodes by name, while a
KindTest
allows selection based on the kind of node (for example, elements, text nodes, or comments) and also (in the case of elements and attributes) its schema-defined type.
Specifying a
NameTest
implicitly causes selection of a particular kind of node: attributes for the attribute axis, namespaces for the namespace axis, and elements in all other cases.
Usage
A
NodeTest
is used in an
AxisStep
to specify the name and/or kind of the nodes to be selected by the
Step
.
In general, you specify either the name of the nodes or their kind. If you specify a
NameTest
, this implicitly selects nodes of the principal node kind for the axis used in the
AxisStep
. For the attribute axis, this selects attribute nodes; for the namespace axis, it selects namespace nodes, and for all other axes, it selects element nodes.
Specifying
node()
as the
KindTest
selects all nodes on the axis. You must specify
node()
if you want the
AxisStep
to select nodes of more than one kind.
Specifying
processing-instruction()
or
comment()
or
text()
as the
KindTest
selects nodes of the specified kind. It doesn't make sense to specify any of these on the attribute or namespace axes, because they can't occur there. These nodes are unnamed, except for processing instructions, which is why there is an option in this single case to specify both the node kind and the node name required.
Examples of Node Tests
Expression | Description |
TITLE | This NameTest selects all attribute::TITLE or @TITLE ), when it selects the TITLE attribute, or with the namespace axis (as namespace::TITLE ), when it selects the namespace node whose prefix is TITLE . |
news:article | This NameTest selects all nodes with local name article within the news namespace. These may be attribute nodes or element nodes, depending on the axis. There must be an enclosing element in the style sheet that declares the news prefix, by having an attribute of the form: xmlns:news = “urn:newsml:iptc.org:20001006: NewsMLv1.0:1” . The node in the source document must have a name that uses this namespace URI, but it does not need to use the same prefix. |