Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Comments and processing instructions (6/9) >

Selecting comments with "node"

The select attribute of xsl:apply-templates in this example has value "node()". The "node()" is the most general node test, it matches a node of any kind. If xsl:apply-templates without select was used there would be no match as the default behavior of xsl:apply-templates does not apply instructions to comments and processing instructions.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/">
                  <xsl:apply-templates  select="node()"/>
            </xsl:template>

            <xsl:template  match="comment()">
                  <xxx>
                        <i>
                              <xsl:text>Node type: comment</xsl:text>
                        </i>
                        <i>
                              <xsl:text>Comment contents: </xsl:text>
                              <xsl:value-of  select="."/>
                        </i>
                  </xxx>
            </xsl:template>

            <xsl:template  match="*">
                  <xxx>
                        <i>
                              <xsl:text>Node type: element</xsl:text>
                        </i>
                        <i>
                              <xsl:text>Element name: </xsl:text>
                              <xsl:value-of  select="name()"/>
                        </i>
                  </xxx>
                  <xsl:apply-templates  select="node()"/>
            </xsl:template>

      </xsl:stylesheet>
XML
<!-- comment A -->
      <aaa> <!-- comment B --> </aaa>
Output

      <xxx>
            <i>Node type: comment</i>
            <i>Comment contents: comment A </i>
      </xxx>
      <xxx>
            <i>Node type: element</i>
            <i>Element name: aaa</i>
      </xxx>
      <xxx>
            <i>Node type: comment</i>
            <i>Comment contents: comment B </i>
      </xxx>


Previous chapter: Date and Time
Next chapter: Built in Types
Previous page: Matching comments in the source document
Next page: Processing instructions

Kevin Carr in Stanton

Natural Skin Care and European Soaps
Kevin Carr
Mayor Dave Shawver Stanton
Internetusers


You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks