16.4 Disabling Output Escaping
Disabling Output Escaping
Normally, the xml output method escapes & and <
(and possibly other characters) when outputting text nodes. This
ensures that the output is well-formed XML. However, it is sometimes
convenient to be able to produce output that is almost, but not quite
well-formed XML; for example, the output may include ill-formed
sections which are intended to be transformed into well-formed XML by
a subsequent non-XML aware process. For this reason, XSLT provides a
mechanism for disabling output escaping. An xsl:value-of
or xsl:text element may have a
disable-output-escaping attribute; the allowed values are
yes or no; the default is no;
if the value is yes, then a text node generated by
instantiating the xsl:value-of or xsl:text
element should be output without any escaping. For example,
<xsl:text disable-output-escaping="yes"><</xsl:text>
should generate the single character <.
It is an error for output escaping to be disabled for a text node
that is used for something other than a text node in the result tree.
Thus, it is an error to disable output escaping for an
xsl:value-of or xsl:text element that is
used to generate the string-value of a comment, processing instruction
or attribute node; it is also an error to convert a Result Tree Fragment to a
number or a string if the result tree fragment contains a text node for
which escaping was disabled. In both cases, an XSLT processor may
signal the error; if it does not signal the error, it must recover by
ignoring the disable-output-escaping attribute.
The disable-output-escaping attribute may be used with
the html output method as well as with the
xml output method. The text output method
ignores the disable-output-escaping attribute, since it
does not perform any output escaping.
An XSLT processor will only be able to disable output escaping if
it controls how the result tree is output. This may not always be the
case. For example, the result tree may be used as the source tree for
another XSLT transformation instead of being output. An XSLT
processor is not required to support disabling output escaping. If an
xsl:value-of or xsl:text specifies that
output escaping should be disabled and the XSLT processor does not
support this, the XSLT processor may signal an error; if it does not
signal an error, it must recover by not disabling output escaping.
If output escaping is disabled for a character that is not
representable in the encoding that the XSLT processor is using for
output, then the XSLT processor may signal an error; if it does not
signal an error, it must recover by not disabling output escaping.
Since disabling output escaping may not work with all XSLT
processors and can result in XML that is not well-formed, it should be
used only when there is no alternative.
|