XPath Node Tests
XPath defines several node tests that can be used to select nodes from the source tree. These node tests allow you to select nodes that can’t be selected any other way. (Although they look and work like functions, they are technically node tests.) The node tests are described here:
text()Selects all the text-node children of the context node.
comment()Selects all the comment-node children of the context node.
processing-instruction()Selects all the processing-instruction children of the context node. Unlike the other node tests defined here,
processing-instruction()can have an optional argument;processing-instruction('xml-stylesheet')selects all processing instructions with a name ofxml-stylesheet.node()Returns all nodes, regardless of type. Using this node test selects all element nodes, attribute nodes, processing-instruction nodes, etc. (Be aware that using
node()on the child axis does not return any attribute nodes, because attributes are not considered child nodes.)- [2.0]
attribute() Returns any attribute. When used with an attribute name (
attribute(public-domain)), it returns all attributes with the specified name. When used with an attribute name and a datatype (attribute(public-domain, xs:boolean)), it returns all attributes with that specified name and datatype. Finally, when used with a wildcard for the attribute name (attribute(*, xs:boolean)), it returns all attributes with the specified datatype.- [2.0]
element() Returns any element. When used with an ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access