1<html><head>
2      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
3   <title>A brief introduction to XSL</title><link rel="stylesheet" href="reference.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.37"><link rel="home" href="index.html" title="DocBook XSL Stylesheet Documentation"><link rel="up" href="publishing.html" title="Chapter 1. DocBook XSL"><link rel="previous" href="publishing.html" title="Chapter 1. DocBook XSL"><link rel="next" href="ch01s03.html" title="XSL processing model"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">A brief introduction to XSL</th></tr><tr><td width="20%" align="left"><a href="publishing.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter 1. DocBook XSL</th><td width="20%" align="right">&nbsp;<a href="ch01s03.html">Next</a></td></tr></table><hr></div><p>XSL is both a transformation language and a
4 formatting language. The XSLT transformation part lets you
5 scan through a document's structure and rearrange its
6 content any way you like. You can write out the content
7 using a different set of XML tags, and generate text as
8 needed. For example, you can scan through a document to
9 locate all headings and then insert a generated table of
10 contents at the beginning of the document, at the same time
11 writing out the content marked up as HTML. XSL is also a
12 rich formatting language, letting you apply typesetting
13 controls to all components of your output. With a good
14 formatting backend, it is capable of producing high quality
15 printed pages.</p><p>An XSL stylesheet is written using XML syntax, and is
16 itself a well-formed XML document. That makes the basic
17 syntax familiar, and enables an XML processor to check for
18 basic syntax errors. The stylesheet instructions use
19 special element names, which typically begin with
20 <tt>xsl:</tt> to distinguish them from any XML
21 tags you want to appear in the output. The XSL namespace is
22 identified at the top of the stylesheet file. As with other
23 XML, any XSL elements that are not empty will require a
24 closing tag. And some XSL elements have specific attributes
25 that control their behavior. It helps to keep a good XSL
26 reference book handy.</p><p>Here is an example of a simple XSL stylesheet applied
27 to a simple XML file to generate HTML output.</p><div class="example"><p><a name="c44b1b3b5b5"></a><b>Example 1.1. Simple XML file</b></p><pre class="programlisting">&lt;?xml version="1.0"?&gt;
28&lt;document&gt;
29&lt;title&gt;Using a mouse&lt;/title&gt;
30&lt;para&gt;It's easy to use a mouse. Just roll it
31around and click the buttons.&lt;/para&gt;
32&lt;/document&gt;</pre></div><div class="example"><p><a name="c44b1b3b5b6"></a><b>Example 1.2. Simple XSL stylesheet</b></p><pre class="programlisting">&lt;?xml version='1.0'?&gt;
33&lt;xsl:stylesheet
34          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'&gt;
35&lt;xsl:output method="html"/&gt;
36
37&lt;xsl:template match="document"&gt;
38  &lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;
39    &lt;xsl:value-of select="/title"/&gt;
40  &lt;/TITLE&gt;
41  &lt;/HEAD&gt;
42  &lt;BODY&gt;
43    &lt;xsl:apply-templates/&gt;
44  &lt;/BODY&gt;
45  &lt;/HTML&gt;
46&lt;/xsl:template&gt;
47
48&lt;xsl:template match="title"&gt;
49  &lt;H1&gt;&lt;xsl:apply-templates/&gt;&lt;/H1&gt;
50&lt;/xsl:template&gt;
51
52&lt;xsl:template match="para"&gt;
53  &lt;P&gt;&lt;xsl:apply-templates/&gt;&lt;/P&gt;
54&lt;/xsl:template&gt;
55
56&lt;/xsl:stylesheet&gt;
57</pre></div><div class="example"><p><a name="c44b1b3b5b7"></a><b>Example 1.3. HTML output</b></p><pre class="programlisting">&lt;HTML&gt;
58&lt;HEAD&gt;
59&lt;TITLE&gt;Using a mouse&lt;/TITLE&gt;
60&lt;/HEAD&gt;
61&lt;BODY&gt;
62&lt;H1&gt;Using a mouse&lt;/H1&gt;
63&lt;P&gt;It's easy to use a mouse. Just roll it
64around and click the buttons.&lt;/P&gt;
65&lt;/BODY&gt;
66&lt;/HTML&gt;
67</pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a href="publishing.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a href="index.html">Home</a></td><td width="40%" align="right">&nbsp;<a href="ch01s03.html">Next</a></td></tr><tr><td width="40%" align="left">Chapter 1. DocBook XSL&nbsp;</td><td width="20%" align="center"><a href="publishing.html">Up</a></td><td width="40%" align="right">&nbsp;XSL processing model</td></tr></table></div></body></html>