Node Tests & Axis Specifiers | ||||||||||||||||
Node tests are most frequently element names, but other node tests are possible: name | ||||||||||||||||
Matches <name> element nodes | ||||||||||||||||
* Matches any element node |
||||||||||||||||
namespace:name | ||||||||||||||||
Matches <name> element nodes in the specified namespace | ||||||||||||||||
namespace:* | ||||||||||||||||
Matches any element node in the specified namespace | ||||||||||||||||
comment() | ||||||||||||||||
Matches comment nodes | ||||||||||||||||
text() | ||||||||||||||||
Matches text nodes | ||||||||||||||||
processing-instruction() | ||||||||||||||||
Matches processing instructions | ||||||||||||||||
processing-instruction(‘target’) | ||||||||||||||||
Matches processing instructions with the specified target (<?target …?> | ||||||||||||||||
node() | ||||||||||||||||
Matches any node | ||||||||||||||||
This table lists seven proprietary XSLT elements created by Microsoft for some of its implementations of the XSLT technology. These are not part of the W3C XSLT standard. | ||||||||||||||||
|
||||||||||||||||
Predicates | ||||||||||||||||
Predicates occur after the node test in square brackets. A wide range of expressions are possible. | ||||||||||||||||
nodetest[1] | ||||||||||||||||
Matches the first node | ||||||||||||||||
Most node tests return nodes in document order, only the tests which select ancestor or preceding elements return nodes in reverse document order. The practical result of this is that the “first” node is almost always the one closest to the context node, although parenthesis can change the effective order. | ||||||||||||||||
nodetest[position()=last()] | ||||||||||||||||
Matches the last node | ||||||||||||||||
nodetest[position() mod 2 = 0] | ||||||||||||||||
Matches even nodes | ||||||||||||||||
element[@id=’foo’] | ||||||||||||||||
Matches the element(s) with id attributes whos value is “foo“ | ||||||||||||||||
element[not(@id)] | ||||||||||||||||
Matches elements that don’t have an id attribute | ||||||||||||||||
author[firstname=”Norman”] | ||||||||||||||||
Match <author> elements that have <firstname> children with the content “Norman“. | ||||||||||||||||
author[normalize-space(firstname)=”Norman”] | ||||||||||||||||
Match “Norman” without regard to leading and trailing space. Predicate expressions can be more-or-less arbitrarily complex. | ||||||||||||||||
Axis Specifiers | ||||||||||||||||
The axis of a node test determines what general category of nodes may be considered for the following node test. There are thirteen axes: | ||||||||||||||||
ancestor Ancestors of the current node ancestor-or-self attribute child descendant descendant-or-self following / following-sibling preceding / preceding-sibling namespace parent self |
||||||||||||||||
The following graphic, courtesy of Crane Softwrights, demonstrates the axes graphically: | ||||||||||||||||
![]() |
||||||||||||||||