Rendering HTML Tags from within CDATA tag in XSL Rendering HTML Tags from within CDATA tag in XSL xml xml

Rendering HTML Tags from within CDATA tag in XSL


<p class="smartText">  <xsl:value-of     select="marketSummaryModuleData/smartText"     disable-output-escaping="yes"  /></p>

EDIT: As @Randell points out in the comments, disable-output-escaping is not present in all XSLT processors. For instance, the one in Firefox does not support this attribute. The above won't work for these processors. All stand-alone XSLT processors I know support it, though.


You have to correct the XML so that the desired HTML (and it needs to be well-formed XML) is not contained within a CDATA section.

Any CDATA section is just part of a text() node and the XSLT processor treats it as such.

Putting markup within CDATA is universally acknowledged as bad practice and the reported issue is one typical result.

DOE (disable-output-escaping) is an optional feature in XSLT and is not guaranteed to be implemented and producing the same expected results on different XSLT processors.

To quote the W3C XSLT Spec.:

"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."

and:

"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."


<xsl:for-each select="marketSummaryModuleData/smartText">    <xsl:copy-of select="node()"/></xsl:for-each><smartText>Among individual stocks, the top percentage gainers in the S.&P. 500 are<a href ='http://investing.domain.com/research/stocks/snapshot/snapshot.asp?ric=LNC'>Lincoln National Corp</a> and <a href ='http://investing.domain.com/research/stocks/snapshot/snapshot.asp?ric=PLD'>ProLogis</a>.</smartText>