WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 5 (1/4)
[next] |
Inside XSLT
Choosing Output Methods
[Editor's note: the following is a continuation of our series of excerpts from chapter 2 of the New Riders publication, "Inside XSLT."]
Another important aspect of writing stylesheets is picking the output method:
XML, HTML, text (that is, any kind of text-based document that is not XML or HTML), and so
on. In other words, the output method determines the type of document you're creating.
By default, the output method is XML, although most processors create HTML documents if
they see a <HTML>
element. (Some processors also do this if
the extension of the document file you're creating is .html.)
Chapter 6 discusses how this works in depth, but I'll look at this topic in
overview now. Unless you are sure that the default output type rules of your XSLT processor
are doing what they should, it's often advisable to set the output type explicitly to match
the kind of output document you want, using the <xsl:output>
element. The
output type can determine, for example, whether the XSLT processor writes the XML processing
instruction, <?xml version="1.0"?>
, at the beginning of the document, and
it can determine the MIME type (such as "text/xml" or "text/html") of documents sent back
from an XSLT processor on a Web server to a browser. In addition, if you set the output type
to HTML, most XSLT processors recognize that not all elements in HTML need closing as well
as opening tags, and so on.
Chapter 6 is about converting from XML to other document types, but I'll take a
look at <xsl-output>
in overview here because it's important to understand
when working with stylesheets in general. The following list includes the attributes of
<xsl-output>
:
cdata-section-elements
(optional). Sets the names of those elements whose content you want output as CDATA sections. Set to a whitespace-separated list ofQNames
.doctype-public
(optional). Specifies the public identifier to be used in the<!DOCTYPE>
declaration in the output. Set to a string value.doctype-system
(optional). Specifies the system identifier to be used in the<!DOCTYPE>
declaration in the output. Set to a string value.encoding
(optional). Sets the character encoding. Set to a string value.indent
(optional). Specifies whether the output should be indented to show its nesting structure. Set to "yes" or "no".media-type
(optional). Sets the MIME type of the output. Set to a string value.method
(optional). Sets the output format. Set to "xml", "html", "text", or a validQName
.omit-xml-declaration
(optional). Specifies whether the XML declaration should be included in the output. Set to "yes" or "no".standalone
(optional). Specifies whether a standalone declaration should be included in the output and sets its value if so. Set to "yes" or "no".version
(optional). Sets the version of the output. Set to a validNMToken
.
The most-used attribute of this element is method
, because that's what
you use to set the output tree type you want. The three most common settings are "html", "xml",
and "text".
[next] |
Created: October 11, 2001
Revised: October 11, 2001
URL: https://webreference.com/authoring/languages/xml/insidexslt/chap2/5/