Datasheet
Williams c01.tex V3 - 07/31/2009 2:53pm Page 5
Chapter 1: First Steps with XSLT
You can define the type of output in the declaration <
xsl:output>
. You saw the schema definition in
this book’s introduction, but here it is as a reminder. The attribute list is quite extensive, but for now I’d
like to focus on just a few attributes:
<xs:element name
=
"output" substitutionGroup
=
"xsl:declaration">
<xs:complexType mixed
=
"true">
<xs:complexContent mixed
=
"true">
<xs:extension base
=
"xsl:generic-element-type">
<xs:attribute name
=
"name" type
=
"xsl:QName"/>
<xs:attribute name
=
"method" type
=
"xsl:method"/>
<xs:attribute name
=
"byte-order-mark" type
=
"xsl:yes-or-no"/>
<xs:attribute name
=
"cdata-section-elements" type
=
"xsl:QNames"/>
<xs:attribute name
=
"doctype-public" type
=
"xs:string"/>
<xs:attribute name
=
"doctype-system" type
=
"xs:string"/>
<xs:attribute name
=
"encoding" type
=
"xs:string"/>
<xs:attribute name
=
"escape-uri-attributes" type
=
"xsl:yes-or-no"/>
<xs:attribute name
=
"include-content-type" type
=
"xsl:yes-or-no"/>
<xs:attribute name
=
"indent" type
=
"xsl:yes-or-no"/>
<xs:attribute name
=
"media-type" type
=
"xs:string"/>
<xs:attribute name
=
"normalization-form" type
=
"xs:NMTOKEN"/>
<xs:attribute name
=
"omit-xml-declaration" type
=
"xsl:yes-or-no"/>
<xs:attribute name
=
"standalone" type
=
"xsl:yes-or-no-or-omit"/>
<xs:attribute name
=
"undeclare-prefixes" type
=
"xsl:yes-or-no"/>
<xs:attribute name
=
"use-character-maps" type
=
"xsl:QNames"/>
<xs:attribute name
=
"version" type
=
"xs:NMTOKEN"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
In XSLT 1.0, the
method
attribute can take the values
"xml", "html"
,or
"text"
. For instance, you
would use the
"text"
method to output a CSV file, which you’ll learn how to do in Chapter 9. You
would use
"xml"
as a value for SVG output, and also for PDF because it requires transforming to the
XSLFO format as an intermediate step. The XSLT 2.0 specification adds
"xhtml"
to the possible attribute
values.
However, in the next XSLT 1.0 example you’ll use
"xml"
as a value, as the output is XHTML.
The
version
attribute on the
<xsl:stylesheet>
element is rather confusing. It has absolutely nothing
to do with the version of XSLT; rather, it refers to the version of XML to be output.
You can define an
encoding
attribute, which specifies the preferred character encoding of the output
document. All XSLT processors (and XML parsers) are required to support UTF-8 and UTF-16. Clearly,
processing Chinese or Japanese content with UTF-8 encoding would produce corrupt output.
On this occasion, you’ll set it to
‘UTF-8’
. You can also add two more attributes specifying the XHTML
doctype-system
and
doctype-public
attribute values. These will result in the processor generating
correct declarations in the output, before the
<html>
element:
<xml version
=
"1.0" encoding
=
"UTF-8"/>
<xsl:stylesheet
xmlns:xsl
=
http://www.w3.org/1999/XSL/Transform
5