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"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

</xsl:stylesheet>

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 http://www.w3.org/1999/XSL/Transform. 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 ...

Get XSLT 1.0 Pocket Reference 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.