XSLT <xsl:output> element

Definition and Usage

The <xsl:output> element defines the format of the output document.

Note:<xsl:output> is a top-level element (top-level element), and must be a child node of <xsl:stylesheet> or <xsl:transform>.

Syntax

<xsl:output
method="xml|html|text|name"
version="string"
encoding="string"
omit-xml-declaration="yes|no"
standalone="yes|no"
doctype-public="string"
doctype-system="string"
cdata-section-elements="namelist"
indent="yes|no"
media-type="string"/>

Attribute

Attribute Value Description
method
  • xml
  • html
  • text
  • name
Optional. Defines the output format. The default is XML. Netscape 6 supports only 'html' and 'xml'.
version string Optional. Sets the W3C version number of the output format. (Used only when method="html" or method="xml").
encoding string Optional. Sets the value of the encoding attribute in the output.
omit-xml-declaration
  • yes
  • no

Optional.

"yes" specifies that the XML declaration should be omitted from the output (<?xml...?>).

"no" specifies that the XML declaration should be included in the output. The default is 'no'.

standalone
    • yes
    • no
Optional. Specifies whether the XSLT processor should output an independent document declaration; this value must be 'yes' or 'no'. The default is 'no'. Netscape 6 does not support this attribute.
doctype-public string Optional. Specifies the public identifier to be used in the DTD. That is, the value of the PUBLIC attribute in the DOCTYPE declaration in the output.
doctype-system string Optional. Specifies the system identifier to be used in the DTD. That is, the value of the SYSTEM attribute in the DOCTYPE declaration in the output.
cdata-section-elements namelist Optional. A space-separated list of elements, whose text content should be output as CDATA sections.
indent
  • yes
  • no
Optional. Specifies whether to add whitespace when outputting the result tree; the value must be yes or no. Netscape 6 does not support this attribute.
media-type string Optional. Defines the MIME type (media type of the data) of the output. The default is "text/xml". Netscape 6 does not support this attribute.

method attribute

Identifies the overall method used for outputting the result tree. If there is no prefix, it identifies the method specified in this document, which must be "xml", "html", "text", or one of the non-NCName qualified names). If there is a prefix, it expands and identifies the output method.

The selection of the default value of the method attribute is as follows. If any of the following conditions is true, the default output method is "html":

The root node of the result tree contains element children.

The extended name of the first element child (i.e., the document element) of the root node in the result tree contains the local part "html" (any combination of case) and an empty namespace URI.

Any text node before the first element child of the root node in the result tree only contains whitespace characters.

Otherwise, the default output method is "xml". If there is no <xsl:output> element or if the <xsl:output> element does not specify the value of the method attribute, the default output method should be used.

Instance

Example 1

In this example, the output is an XML document, version 1.0. The character encoding is set to "ISO-8859-1", and the output is indented to enhance readability:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
...
...
</xsl:stylesheet>

Example 2

In this example, the output is an HTML document, version 4.0. The character encoding is set to "ISO-8859-1", and the output is indented to enhance readability:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>
...
...
</xsl:stylesheet>