XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / First XSLT transformations / Three documents are involved

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)

Every transformation involves three documents. First, the source document, an XML document containing the information to process. Second, the XSLT stylesheet, specifying how to handle the source information. Third, the result document produced after transformation; its structure depends on the stylesheet instructions and the source document’s structure and content.

The source document

A source document is required for a transformation. We use a very simple XML file to avoid distraction. An empty root element would suffice, but the demonstrations should have a little content:

Code example: kap01/1.02.1/dummy.xml.

<?xml version="1.0" encoding="ISO-8859-1"?>
<wurzelelement>Das ist ein Testinhalt aus 'dummy.xml'.</wurzelelement>

Note: Briefly, the input XML parser, always preceding transformation, converts the document internally into a tree. This is not important yet, but will help explain processing later.

The stylesheet

Document dummy.xml is processed using an XSLT stylesheet, also kept as simple as possible for this introductory example; see the figure:

The first stylesheet stylesheet1.xsl

Figure: The first stylesheet “stylesheet1.xsl”.

Some element names clearly begin with xsl:. Here, elements xsl:stylesheet in light gray and xsl:template in medium gray form the stylesheet’s functional framework. Inside xsl:template is also ordinary HTML, in dark gray. The XML prolog identifies the stylesheet as XML. Attribute encoding specifies the document’s character set.

The result document

This result is generated, here a simple HTML document:

Code example: kap01/1.02.1/ergebnis.html.

<html>    
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
    <title>Ergebnisdokument</title>
  </head>
  <body>
    <h1>Die erste XSLT-Transformation</h1>
    <p>Ein Textabsatz. Später mehr.</p>
  </body>
</html>

Comparing the result and stylesheet shows that almost the entire result already appears in the stylesheet, wrapped in other elements and shown in dark gray. This part was evidently copied, but a tag <meta> absent from the stylesheet was added.

This near-total copying is an extreme case. Equally extreme, the XML source seems unused, though it contains almost nothing. It nevertheless plays a role, as we will see later.

For now, note that stylesheet regions reappear unchanged in the result. Because they are taken literally, they are called Literal Result Elements (literal result elements).

Copying Literal Result Elements

Figure: Copying Literal Result Elements.

   

back to top