tags:

views:

2837

answers:

3

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'&gt;ProLogis&lt;/a&gt; and <a href ='http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ric=LNC'&gt;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

+5  A: 
<p class="smartText">
  <xsl:value-of 
    select="marketSummaryModuleData/smartText" 
    disable-output-escaping="yes"
  />
</p>
Tomalak
+1  A: 
Dimitre Novatchev
Independently of whether it is a bad practice or not - won't "disable-output-escaping" do what the OP is after?
Tomalak
@Tomalak: Yes it works fine.
AnthonyWJones
@Dimitre: It depends on the source of the HTML, it could be the html comes from a source not compliant with HTML formed well enough to be included as-is in a XML document. If the XML document is merely message transport I can't see using a CDATA as a "bad practice".
AnthonyWJones
@Tomalak and @AnthonyWJones Your comments were on the first version of my answer. Since then I edited it and probably it now answers your questions.
Dimitre Novatchev
@Tomalak d-o-e may or maynot solve the OP's problem, depending on which XSLT processor (s)he is using.
Dimitre Novatchev
disable-output-escaping does work, but not in all browsers. Since this module will be used by thousands of people, it will need to work in all browsers. It looks like I will need to take the data in my ASP code and parse it into multiple tags instead of one large string of text.
Shane Larson
@Shane: you should add the detail that you need to work in all browsers in your question. Would a server-side transform work for you?
AnthonyWJones
It would be nice to transform on the server side, but since this is a cross-domain solution, it will need to be transformed on the client-side.
Shane Larson
Since this segment has the most information in it I am marking this as the right answer.The other answer is correct too, but not for all browsers. Was trying to take a shortcut by inserting HTML into the tags, but now I've realized that I really need to break out the info into well formed XML.
Shane Larson
Good answer, but your edit at the end makes me want to down vote you. Right or wrong, lashing out at a single down-voter just makes you look petty.
Liam
@Liam: This was done a year and a half ago, when I was a SO newbie... Even now, I think it expresses well my feelings towards anonymous downvoting, but nowadays I wouldn't have time to indulge in such conversations. For good or for bad. If ugly deeds continue to happen this is because they are allowed by the system. One thing that we can all learn here is to suppress our emotions -- something easier to say than really do. Anyway, this serves well as a historic stamp of where I stood some time ago. As for looking petty: isn't this slightly relative? Anyone may look petty, even photomodels :)
Dimitre Novatchev
A: 

I did the same but it does not work for me.. is there any specific reason?...