Datasheet

Williams c01.tex V3 - 07/31/2009 2:53pm Page 2
Chapter 1: First Steps with XSLT
If you haven’t already done so, download the source code for this book from this book’s web page at
www.wrox.com
. You’ll be using the source files from now on in the examples that follow. When you’ve
unzipped the download, open the folder for Chapter 1 and locate the file
xml_stylesheet.xml
.
Listing 1-1 shows a pared-down version of the source document describing the
<xsl:stylesheet>
element.
Listing 1-1
<?xml version
=
"1.0" encoding
=
"UTF-8"?>
<reference>
<body>
<title>xsl:stylesheet</title>
<purpose>
<p>The root element of a stylesheet.</p>
</purpose>
<usage>
<p>The <element>stylesheet</element> is always the root element, even if
a stylesheet is included in, or imported into, another. It must have a
<attr>version</attr> attribute, indicating the version of XSLT that the
stylesheet requires.</p>
<p>For this version of XSLT, the value should normally be "2.0". For a
stylesheet designed to execute under either XSLT 1.0 or XSLT 2.0, create a core
module for each version number; then use <element>xsl:include</element> or
<element>xsl:import</element> to incorporate common code, which should specify
<code>version
=
"2.0"</code> if it uses XSLT 2.0 features, or
<code>version
=
"1.0"</code> otherwise.</p>
<p>The <element>xsl:transform</element> element is allowed as a synonym.</p>
<p>The namespace declaration <code>xmlns:xsl
=
"http//www.w3.org/1999/XSL/
Transform</code> by convention uses the prefix <code>xsl</code>.</p>
<p>An element occurring as a child of the <element>stylesheet</element>
element is called a declaration. These top-level elements are all optional, and
may occur zero or more times.</p>
</usage>
</body>
</reference>
In the quick reference documents I use an XML grammar based on the Darwin Information Typing
Architecture (DITA) reference content model. DITA is finding increasing support among the larger pub-
lishers of technical documentation. It differs considerably from the longer-established DocBook format,
using a more modular approach, covering the concept/task/reference pattern often found in software
help systems. You can look ahead to see details of the schema in Chapter 11. In addition to markup
like
<body>
,
<p>
and
<code>
, which you’ll recognize from XHTML, note that the root element in this
example is <
reference>
. To keep the example simple, only the sections on <
purpose>
and <
usage>
are
included, as are the inline <
attr> (attrib
ute) and <
element>
names. In later chapters I’ll introduce
more elements from the reference vocabulary.
Using a Browser
To run any transform inside a browser, you need to add a processing instruction to the source document,
which will give the browser the location of the stylesheet you want to use. This goes immediately after
the XML declaration in
xsl_stylesheet.xml
. Save the update while you start work on the stylesheet.
2