Matching Element Descendants

In the preceding section, I used the expression "PLANET/NAME" to match all <NAME> elements that are direct children of <PLANET> elements, and the expression "PLANET/*/NAME" to match all <NAME> elements that are grandchildren of <PLANET> elements. However, there’s an easier way to perform both matches: just use the expression "PLANET//NAME", which matches all <NAME> elements that are inside <PLANET> elements, no matter how many levels deep (the matched elements are called descendants of the <PLANET> element). In other words, "PLANET//NAME" matches "PLANET/NAME", "PLANET/*/NAME", "PLANET/*/*/NAME", and so on:

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

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.