Matching Children

You can use the / step operator to separate element names when you want to refer to a child of a particular node. For example, say that you want to create a rule that applies to only those <NAME> elements that are children of <PLANET> elements. In that case, you can match the expression "PLANET/NAME". Here’s a rule that surrounds the text of such elements in a <H3> HTML element:

<xsl:template match="PLANET/NAME"> 
    <H3> 
         <xsl:value-of select="."/> 
    </H3> 
</xsl:template> 

You also can use the * character as a wildcard, standing for any element. (* can match only elements, although note that the pattern @* can match any attribute.) For example, the following rule applies to all <NAME> elements that are grandchildren of <PLANET> ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.