Choose Your Output Format in XSLT
Take control of the output of an XSLT stylesheet.
The output element
in XSLT has 10 attributes, each controlling a different aspect of
XSLT output. This hack lists each of these attributes and shows you
how to use them. All of output’s
attributes are optional.
An XSLT stylesheet can have more than
one output element, and the values found in the
attributes of those elements are combined. However, if a given
attribute occurs on more than one output element,
the last occurrence trumps all previous occurrences. Nevertheless, it
is technically an error if an attribute (aside from
cdata-section-elements) occurs on more than one
output element in the stylesheet; however,
processors can recover by choosing the value from the last
output in the stylesheet.
- Output method
The
methodattribute can have the valuexml,html, ortextfor XML, HTML, and text output, respectively. XSLT 2.0 will support a value ofxhtmlfor XHTML support. The method attribute can also have a QName as a value, but the QName must be recognized by the application processing it. If the first element in the result ishtml, the default method ishtml;xmlif otherwise.- Indentation
The
indentattribute takes the valueyesorno. This tells the XSLT processor to indent the output to the result tree, which helps make output more readable. A value ofyesis the default for thehtmloutput method,nofor thexmloutput method.- XML declaration
The
omit-xml-declarationattribute can have a value of ...