Single-Template Stylesheets

Many useful transformations can be expressed with just a single-root template. We’ll examine the single-template stylesheet here, but we’ll spend the rest of this chapter learning why there’s a world beyond the root template and why it’s worth learning about.

All of the stylesheets we’ve seen so far for transforming XML into HTML either have looked like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
  <!-- The "root" or "main" template -->
  <xsl:template match="/"> 
    <html>
      <body>
        <!-- 
         | Literal result elements and attributes, intermingled with
         | <xsl:for-each>, <xsl:value-of>, attribute value templates, etc.
         +-->
     </body>
    </html>
  <xsl:template>
</xsl:stylesheet>

or have used the simple form of the single-root template stylesheet, which looks like this:

<!-- In the "simple form" of a stylesheet, the root template is implied -->
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <body>
     <!-- 
      | Literal result elements and attributes, intermingled with
      | <xsl:for-each>, <xsl:value-of>, attribute value templates, etc.
      +-->
  </body>
</html>

Tip

When you see the xsl namespace declaration:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

it is natural to think that the XSLT processor will try to access that URL when your stylesheet is processed. However, the declaration is only used as a unique string to identify the namespace for XSLT. If you do not provide this exact string as the namespace URI for the xsl ...

Get Building Oracle XML Applications 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.