Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering HTML Tags from within CDATA tag in XSL

Tags:

xml

cdata

xslt

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

like image 991
Grizzly Peak Software Avatar asked Mar 31 '09 15:03

Grizzly Peak Software


People also ask

Can you use CDATA in HTML?

CDATA is Obsolete. Note that CDATA sections should not be used within HTML; they only work in XML. So do not use it in HTML 5.

What is CDATA in XSL?

The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.


1 Answers

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

like image 110
Tomalak Avatar answered Sep 22 '22 11:09

Tomalak