WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 5 (1/4) | WebReference

WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 5 (1/4)

current pageTo page 2To page 3To page 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>:

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".


current pageTo page 2To page 3To page 4
[next]

Created: October 11, 2001
Revised: October 11, 2001


URL: http://webreference.com/authoring/languages/xml/insidexslt/chap2/5/