Selecting Which Template to Apply

Up to this point, I’ve used only the default version of <xsl:apply-templates>, like this:

<TABLE BORDER="2"> 
    <TR> 
        <TD>Name</TD> 
        <TD>Mass</TD> 
        <TD>Radius</TD> 
        <TD>Day</TD> 
    </TR> 
    <xsl:apply-templates/> 
</TABLE> 

Using <xsl:apply-templates/> alone simply makes the XSLT processor search for all templates that match the child nodes of the context node, and that’s the default usage. However, sometimes that’s not good enough, because you may want to apply templates in a specific order, or otherwise choose what templates to apply, and you do that with the select attribute of the <xsl:apply-templates/>.

For example, so far we’ve only recovered the value of each <MASS>, <DAY>, and <RADIUS> element using <xsl:value-of> ...

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.