Creating a Template

In Chapter 2, I created a basic template to match the nodes in planets.xml and convert that document to HTML. You create templates with <xsl:template> elements in your stylesheets, which specify the rules for the transformations you want to apply. We created a template that matched the <PLANETS> root element by matching the pattern “/PLANETS”, which stands for all <PLANETS> elements that are children of the root node, as follows:

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/PLANETS"> 
        . 
        . 
        . 
    </xsl:template> 
        . 
        . 
        . 
</xsl:stylesheet> 

When the XSLT processor finds a node that matches your template’s pattern, that node becomes the context node for the ...

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.