Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development

  • Print
  • + Share This
From the author of

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:

  1. Type <xsl:template.

  2. Type match="/". The forward slash is a pattern that matches the root node of the XML document.

  3. Type >.

  4. Leave a few lines for specifying what should happen with the XML document.

  5. Type </xsl:template> to complete the root template.

    Figure 5

    The root template is the only template that is invoked automatically by the XSLT processor.

    Figure 6

    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>).

  • + Share This
  • 🔖 Save To Your Account