XSLT - Preserving disable-output-escaping in a copy-of
I seem to be having an issue preserving the disable-output-escaping
when using that value inside of an xsl:copy-of
.
Here's my code:
<xsl:call-template name="Display">
<xsl:with-param name="text">
<xsl:v开发者_运维知识库alue-of select="content" disable-output-escaping="yes" />
</xsl:with-param>
</xsl:call-template>
<xsl:template name="Display">
<xsl:param name="text" />
<span><xsl:copy-of select="$text" /></span>
</xsl:template>
Any special characters that were kept as-is from the xsl:value-of
statement are escaped when they're used in the xsl:copy-of
statement.
For example:
<xsl:value-of select="$text" disable-output-escaping="yes">
will display this: è
<xsl:copy-of select="$text">
will display è
I'd like to know if there is any way around this?
As per Spec, the disable-output-escaping
attribute can be specified only on <xsl:value-of>
and the <xsl:text>
instructions.
You need the DOE only on the xslt instruction that actually outputs the value, not on one that sets a parameter value.
Solution:
Replace:
<span><xsl:copy-of select="$text"/></span>
with:
<span><xsl:value-of select="$text" disable-output-escaping="yes"/></span>
Do note: Typically one should avoid using DOE, as it breaks the XSLT architectural model and usually isn't needed. Also, the DOE feature isn't mandatory and not all XSLT 1.0 processors support it.
Note 2: You don't actually need DOE in your case at all. The output from the XSLT transformation should be displayed by the browser as expected.
disable-output-escaping controls the action of the serializer when handed a text node. It's meaningless when the text node isn't being handed to a serializer, for example when it is added to a temporary tree.
精彩评论