xsl:output

Specifies the output for the result tree.

Format

<xsl:output attribute_list />
               

            

Description

The xsl:output instruction specifies how you want the result tree to be output. However, if you use the XSLT processor to format the result as a string, or to generate DOM nodes, the xsl:output instruction has no effect.

If you specify the xsl:output instruction, the XSLT processor outputs the result tree according to your specification. If you specify it, the xsl:output instruction must be a top-level element.

The attribute list can include the method attribute. The method attribute identifies the overall method you want the XSLT processor to use to output the result tree. The value must be xml, html, or text.

  • xml formats the result tree as XML.
  • html formats the result tree as HTML. The stylesheet applies special formatting rules for empty tags, binary attributes, and character escaping, among other things. The values of the attributes named href and src are URL encoded.
  • text concatenates the text nodes in the result tree. The concatenated string does not include any tags.

Note that the XSLT processor formats the results of applying the stylesheet. If your stylesheet generates XML or HTML that does not follow all syntax rules, the XSLT processor does not do anything to fix this. For example, if a stylesheet generates multiple root elements, the XSLT processor neither fixes this nor generates an error. You receive a string, and it is only upon examination or use of the string that you would learn that it is not well-formed XML.

If you do not specify an xsl:output instruction that includes the method attribute, the XSLT processor chooses a default as follows:

  • html is the default output method if the name of the first element child of the root node is html.
  • text is the default output method if the root node has no element child nodes.
  • xml is the default output method in all other cases.

The other attributes that you can specify in attribute_list provide parameters for the output method. You can specify the following attributes:

  • doctype-public specifies the public identifier to be used in the document type declaration.
  • doctype-system specifies the system identifier to be used in the document type declaration.
  • encoding specifies the preferred character encoding that the XSLT processor should use to encode sequences of characters as sequences of bytes.
  • indent specifies whether the XSLT processor can add additional white space when outputting the result tree. The value must be yes or no.
  • media-type specifies the media type (MIME content type) of the data that results from outputting the result tree. Do not explicitly specify the charset parameter. Instead, when the top-level media type is text, add a charset parameter according to the character encoding actually used by the output method.
  • omit-xml-declaration specifies whether the XSLT processor should omit or output an XML declaration. The value must be yes or no. If you do not specify this attribute, whether or not the output contains an XML declaration depends on the output method.
    • If the output method is html, the XSLT processor does not insert an XML declaration.
    • If the output method is xml, the XSLT processor inserts an XML declaration.

The XSLT processor ignores this attribute when the output method is text.

  • standalone specifies whether the XSLT processor should output a stand-alone document declaration. The value must be yes or no.
  • use-character-map specifies the name, if any, of the character map you want to use for the output. A character map substitutes characters based on character/string mappings declared in the xsl:character-map element.

A stylesheet can include multiple xsl:output elements. The XSLT processor effectively merges multiple xsl:output elements into one xsl:output element. If there are multiple values for the same attribute, the XSLT processor uses the last specified value.

Ignored attributes

In this release, the XSLT processor ignores the following attributes:

  • cdata-section-elements specifies a list of the names of elements whose text node children should be output using CDATA sections.
  • version specifies the version of the output method.
 
Free Stylus Studio XML Training: