O'Reilly logo

XSLT by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Stylesheet Structure

As the final part of our introduction to XSLT, we’ll look at the contents of the stylesheet itself. We’ll explain all the things in our stylesheet and discuss other approaches we could have taken.

The <xsl:stylesheet> Element

The <xsl:stylesheet> element is typically the root element of an XSLT stylesheet.

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

First of all, the <xsl:stylesheet> element defines the version of XSLT we’re using, along with a definition of the xsl namespace. To be compliant with the XSLT specification, your stylesheet should always begin with this element, coded exactly as shown here. Some stylesheet processors, notably Xalan, issue a warning message if your <xsl:stylesheet> element doesn’t have these two attributes with these two values. For all examples in this book, we’ll start the stylesheet with this exact element, defining other namespaces as needed.

The <xsl:output> Element

Next, we specify the output method. The XSLT specification defines three output methods: xml, html, and text. We’re creating an HTML document, so HTML is the output method we want to use. In addition to these three methods, an XSLT processor is free to define its own output methods, so check your XSLT processor’s documentation to see if you have any other options.

<xsl:output method="html"/>

A variety of attributes are used with the different output methods. For example, if you’re using method="xml", you can use doctype-public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required