When constructing patterns, you can use names of nodes as node tests, or the wild card * to select any element node. For example, the expression child::*/child:: NAME selects all <NAME> elements that are grandchildren of the context node. In addition to node names and the wild card character, you can also use these node tests in XPath, just as you can in match patterns:
The comment() node test selects comment nodes.
The node() node test selects any type of node.
The processing-instruction() node test selects a processing instruction node. You specify the name of the processing instruction to select in the parentheses.
The text() node test selects a text node.
For example, the following stylesheet finds all comments in a document, using the comment() node test, and creates a new comment, <!--Warning:comment found!--> , for each one:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:for-each select="descendant::comment()"> <xsl:comment>Warning: comment found!</xsl:comment> </xsl:for-each> </xsl:template> </xsl:stylesheet>
Heres the result document when you use this stylesheet on planets.xml:
<?xml version="1.0" encoding="UTF-8"?> <!--Warning: comment found!--> <!--Warning: comment found!--> <!--Warning: comment found!-->