Rendering HTML Tags from within CDATA tag in XSL

Grizzly Peak Software picture Grizzly Peak Software · Mar 31, 2009 · Viewed 16.9k times · Source

I have a CDATA tag within my XML code which contains some hyperlinks.

<smartText><![CDATA[
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>

I am trying to transform it into an HTML page as follows...

<p class="smartText">
    <xsl:copy-of select="marketSummaryModuleData/smartText"/>                                    
</p>    

Unfortunately the output onto the page shows up in pure text, not as html.

Among individual stocks, the top percentage gainers in the S.&P. 500 are <a href ='http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric=PLD'>ProLogis</a> and <a href ='http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric=LNC'>Lincoln National Corp</a>.

The CDATA section is being created from a classic ASP page, so the actual XML output does not contain the CDATA section. Could that be part of the problem? I cannot seem to get the information to render on the page. I have tried multiple solutions offered up by Google searches, such as disable-escape-tags, xsl:copy-of, xsl:value-of and more.

Thank you

Answer

Tomalak picture Tomalak · Mar 31, 2009
<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.