- Transforming XML with XSLT
- Beginning an XSLT Style Sheet
- Creating the Root Template
- Outputting HTML Code
- Outputting a Node's Content
Creating the Root Template
The first thing that the XSLT processor looks for in a style sheet is a template that it can apply to the root node of the XML document. I call this template the root template. To create the root template:
-
Type <xsl:template.
-
Type match="/". The forward slash is a pattern that matches the root node of the XML document.
-
Type >.
-
Leave a few lines for specifying what should happen with the XML document.
-
Type </xsl:template> to complete the root template.
The root template is the only template that is invoked automatically by the XSLT processor.
If you process an XML document with this style sheet and most basic of root templates, you'll get an empty document. That's what the template in Figure 5 says: output two blank lines.
Tips
-
While the XSLT processor doesn't really care where this template appears in your XSLT style sheet, it's probably most clear to you (and people who work with you) if you put it up at the very top.
-
If you do not include a template that matches the root node of the XML document, a built-in template is used which basically tries to find appropriate templates for each of the root node's child nodes. (This built-in root template is equivalent to <xsl:template><xsl:apply-templates/></ xsl:template>).