<html>
<head>
<title>&lt;xsl:output&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:output&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Defines the characteristics of the output document.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Top-level element</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
method
</dt>
<dd>
Typically has one of three values:
<span class="LITERAL">
xml
</span>
,
<span class="LITERAL">
html
</span>
, or
<span class="LITERAL">
text
</span>
. This value indicates the type of document that is generated. An XSLT processor can add other values to this list; how those values affect the generated document is determined by the XSLT processor.
<P></p>
<dt>
version
</dt>
<dd>
Defines the value of the
<span class="LITERAL">
version
</span>
attribute of the XML or HTML declaration in the output document. This attribute is used only when
<span class="LITERAL">
method=
"
html
"
</span>
or
<span class="LITERAL">
method=
"
xml
"
</span>
.
<P></p>
<dt>
encoding
</dt>
<dd>
Defines the value of the
<span class="LITERAL">
encoding
</span>
attribute of the XML declaration in the output document.
<P></p>
<dt>
omit-xml-declaration
</dt>
<dd>
Defines whether the XML declaration is omitted in the output document. Allowable values are
<span class="LITERAL">
yes
</span>
and
<span class="LITERAL">
no
</span>
. This attribute is used only when
<span class="LITERAL">
method=
"
xml
"
</span>
.
<P></p>
<dt>
standalone
</dt>
<dd>
Defines the value of the
<span class="LITERAL">
standalone
</span>
attribute of the XML declaration in the output document. Valid values are
<span class="LITERAL">
yes
</span>
and
<span class="LITERAL">
no
</span>
. This attribute is used only when
<span class="LITERAL">
method=
"
xml
"
</span>
.
<P></p>
<dt>
doctype-public
</dt>
<dd>
Defines the value of the
<span class="LITERAL">
PUBLIC
</span>
attribute of the
<span class="LITERAL">
DOCTYPE
</span>
declaration in the output document. This attribute defines the public identifier of the output document's DTD. It is used only when
<span class="LITERAL">
method=
"
html
"
</span>
or
<span class="LITERAL">
method=
"
xml
"
</span>
.
<P></p>
<dt>
doctype-system
</dt>
<dd>
Defines the value of the
<span class="LITERAL">
SYSTEM
</span>
attribute of the
<span class="LITERAL">
DOCTYPE
</span>
declaration in the output document. It defines the system identifier of the output document's DTD. This attribute is used only when
<span class="LITERAL">
method=
"
html
"
</span>
or
<span class="LITERAL">
method=
"
xml
"
</span>
.
<P></p>
<dt>
cdata-section-elements
</dt>
<dd>
Lists the elements that should be written as
<span class="LITERAL">
CDATA
</span>
sections in the output document. All restrictions and escaping conventions of
<span class="LITERAL">
CDATA
</span>
sections are handled by the XSLT processor. If you need to list more than one element, separate the element names with one or more whitespace characters. This attribute is used only when
<span class="LITERAL">
method=
"
xml
"
</span>
.
<P></p>
<dt>
indent
</dt>
<dd>
Specifies whether the tags in the output document should be indented. Allowable values are
<span class="LITERAL">
yes
</span>
and
<span class="LITERAL">
no
</span>
. This attribute is used only when
<span class="LITERAL">
method=
"
xml
"
</span>
or
<span class="LITERAL">
method=
"
html
"
</span>
, and the XSLT processor is not required to honor it.
<P></p>
<dt>
media-type
</dt>
<dd>
Defines the MIME type of the output document.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None. <span class="LITERAL">&lt;xsl:output&gt;</span> is an empty element.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:output&gt;</span> is a top-level element and can only appear as a child of <span class="LITERAL">&lt;xsl:stylesheet&gt;</span>. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 16, Output. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>To illustrate the three output methods defined in the XSLT specification, we'll create three stylesheets, each of which uses one of the three methods. We'll use the following XML document in all three examples:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list&gt;
  &lt;title&gt;A few of my favorite albums&lt;/title&gt;
  &lt;listitem&gt;A Love Supreme&lt;/listitem&gt;
  &lt;listitem&gt;Beat Crazy&lt;/listitem&gt;
  &lt;listitem&gt;Here Come the Warm Jets&lt;/listitem&gt;
  &lt;listitem&gt;Kind of Blue&lt;/listitem&gt;
  &lt;listitem&gt;London Calling&lt;/listitem&gt;
  &lt;listitem&gt;Remain in Light&lt;/listitem&gt;
  &lt;listitem&gt;The Joshua Tree&lt;/listitem&gt;
  &lt;listitem&gt;The Indestructible Beat of Soweto&lt;/listitem&gt;
&lt;/list&gt;</pre></span>
<p>We'll now look at our three stylesheets and the results produced by each. First, let's look at the <span class="LITERAL">method="xml"</span> stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output 
    method="xml" 
    doctype-public="-//W3C/DTD XHTML 1.0//EN"
    doctype-system="file:///d:/xhtml.dtd"
    encoding="ISO-8859-1"
    indent="no"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;&lt;xsl:value-of select="/list/title"/&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;h1&gt;&lt;xsl:value-of select="/list/title"/&gt;&lt;/h1&gt;
        &lt;p&gt;
          &lt;xsl:for-each select="/list/listitem"&gt;
            &lt;xsl:number format="1. "/&gt;
            &lt;xsl:value-of select="."/&gt;
            &lt;br/&gt;
          &lt;/xsl:for-each&gt;
        &lt;/p&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>This stylesheet generates the following results:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0//EN" "file:///d:/xhtml.dtd"&gt; 
&lt;html&gt;&lt;head&gt;&lt;title&gt;A few of my favorite albums&lt;/title&gt; 
&lt;/head&gt;&lt;body&gt;&lt;h1&gt;A few of my favorite albums&lt;/h1&gt; 
&lt;p&gt;1. A Love Supreme&lt;br/&gt;2. Beat Crazy&lt;br/&gt;3. Here Come the  
Warm Jets&lt;br/&gt;4. Kind of Blue&lt;br/&gt;5. London Calling&lt;br/&gt;6. 
Remain in Light&lt;br/&gt;7. The Joshua Tree&lt;br/&gt;8. The Indestructible  
Beat of Soweto&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre></span>
<p>(We actually added line breaks to this listing; the original output put everything from <span class="LITERAL">&lt;html&gt;</span> through <span class="LITERAL">&lt;/html&gt;</span> on a single line.)</p><p>The output document has the <span class="LITERAL">encoding</span> we specified in our stylesheet, and the <span class="LITERAL">DOCTYPE</span> declaration includes the <span class="LITERAL">PUBLIC</span> and <span class="LITERAL">SYSTEM</span> identifiers we requested as well. Even with the line breaks we added, it's still obvious that this document has not been formatted with any extra whitespace whatsoever. We also have empty <span class="LITERAL">&lt;br/&gt;</span> elements in our output document; those elements will be handled differently when we specify <span class="LITERAL">method="html"</span>. Speaking of which, here is our <span class="LITERAL">method="html"</span> stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output 
    method="html" 
    encoding="ISO-8859-1"
    doctype-public="-//W3C/DTD HTML 1.0 Transitional//EN"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;&lt;xsl:value-of select="/list/title"/&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;h1&gt;&lt;xsl:value-of select="/list/title"/&gt;&lt;/h1&gt;
        &lt;p&gt;
          &lt;xsl:for-each select="/list/listitem"&gt;
            &lt;xsl:number format="1. "/&gt;
            &lt;xsl:value-of select="."/&gt;
            &lt;br/&gt;
          &lt;/xsl:for-each&gt;
        &lt;/p&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Here is the HTML document generated by this stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 1.0 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
&lt;title&gt;A few of my favorite albums&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;A few of my favorite albums&lt;/h1&gt;
&lt;p&gt;1. A Love Supreme&lt;br&gt;2. Beat Crazy&lt;br&gt;3. Here Come 
the Warm Jets&lt;br&gt;4. Kind of Blue&lt;br&gt;5. London Calling&lt;br&gt;6. 
Remain in Light&lt;br&gt;7. The Joshua Tree&lt;br&gt;8. The Indestructible 
Beat of Soweto&lt;br&gt;
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></span>
<p>(As before, we added line breaks to make the listing legible.)  Notice that the XSLT processor has automatically inserted a <span class="LITERAL">&lt;META&gt;</span> element in the <span class="LITERAL">&lt;head&gt;</span> of our HTML document. The <span class="LITERAL">&lt;br&gt;</span> elements that were empty in our previous stylesheet are now old-fashioned <span class="LITERAL">&lt;br&gt;</span> tags. Even though this style of XSLT output results in a document that is not valid XML (or XHTML), the document will work with existing HTML browsers. </p>
<p>Our final stylesheet will use <span class="LITERAL">method="text"</span>:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;&lt;xsl:value-of select="/list/title"/&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;h1&gt;&lt;xsl:value-of select="/list/title"/&gt;&lt;/h1&gt;
        &lt;p&gt;
          &lt;xsl:for-each select="/list/listitem"&gt;
            &lt;xsl:number format="1. "/&gt;
            &lt;xsl:value-of select="."/&gt;
            &lt;br/&gt;
          &lt;/xsl:for-each&gt;
        &lt;/p&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Here are the results, such as they are, from this stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
A few of my favorite albumsA few of my favorite albums1. A Love Supreme2. Beat 
Crazy3. Here Come the Warm Jets4. Kind of Blue5. London Calling6. Remain in 
Light7. The Joshua Tree8. The Indestructible Beat of Soweto</pre></span>
<p>(As before, we inserted line breaks so the document would fit on the page.)  These results are basically worthless. Why weren't our carefully coded HTML elements output to the text document?  The reason is that the <span class="LITERAL">text</span> output method only outputs text nodes to the result tree. Even though we requested that various HTML elements be generated along the way, they're ignored because we specified <span class="LITERAL">method="text"</span>.</p>
</td>
</tr>
</table>
</div>
</body>
</html>