Chapter 3. How XSLT Works

XSLT is a language for transforming XML documents. As described in Chapter 1, the XSLT processor is concerned with three XPath data model trees: the source tree, the stylesheet tree, and the result tree. Figure 3-1 shows the relationship between these three. The stylesheet and source trees are fed to the XSLT processor, which then produces the result tree.

The three trees present in every XSLT transformation
Figure 3-1. The three trees present in every XSLT transformation

Stylesheet Structure

The general structure of an XSLT stylesheet looks like this:

<xsl:stylesheet version="1.0"

  <!-- optional top-level elements, such as: -->
  <xsl:import href="..."/>
  <xsl:param name="..."/>

  <!-- set of template rules: -->
  <xsl:template match="...">...</xsl:template>
  <xsl:template match="...">...</xsl:template>


The document, or root, element of the stylesheet is xsl:stylesheet. Alternatively, you can use the xsl:transform element, which behaves exactly the same way. Which you use is a matter of personal preference. The XSLT namespace is The conventional namespace prefix is xsl, but any prefix can be used—provided that it binds to the XSLT namespace URI.

See Chapter 4 for a classification of all of XSLT’s elements and where they can occur within a stylesheet.

Processing Model

All XSLT processing consists of iterations over ...

Get XSLT 1.0 Pocket Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.