PDA

View Full Version : Render HTML inside CDATA with XSL


dingco
09-10-2006, 05:29 PM
Hi, I'm trying to style my Atom 1.0 feed with XSL.
I need to use <![cdata[...]]> to prevent special characters to create a parse error.
But then HTML tags inside <![cdata[...]]> aren't recognized by any browser.

That's the part of my Atom 1.0 feed :

<summary type="xhtml">
<![cdata[
<div xmlns="http://www.w3.org/1999/xhtml">
my content
</div>
]]>
</summary>

and I get :

<div xmlns="http://www.w3.org/1999/xhtml">
my content
</div>

instead of :

my content


Using <xsl:value-of select="atom:summary"/>
I tried several ways to get it work, but none did :

method="text"
cdata-section-elements="atom:summary"
disable-output-escaping="yes"
<summary type="xhtml"><![cdata[<div xmlns="http://www.w3.org/1999/xhtml">my content</div>]]></summary>

I took example on my feedburner feed.
Their BrowserFriendly feature (which is just an XSL in fact) works fine on my feed,
but once I copy locally my feedburner feed (the XML file) and try to view it still using their XSL (http://feeds.feedburner.com/~d/styles/atom10full.xsl), it's broken, HTML tags aren't recognized.

zcorpan
09-11-2006, 12:13 AM
Your feed is invalid, you should either use type="html" or drop the CDATA section. Further, "<![cdata[" isn't even well-formed XML.

dingco
09-11-2006, 12:28 AM
How so ?

shyam
09-11-2006, 01:09 PM
i've a similar problem too

i tried using
<xsl:value-of select="//.." disable-output-escaping="yes" />

this seems to work in ie but firefox displays the tags as such :(

zcorpan
09-12-2006, 01:48 AM
How so ?

Because that's what the spec (http://www.ietf.org/rfc/rfc4287.txt) says (see 3.1.1.3.). type="xhtml" requires an xhtml:div element as a child, not text.

As for <![cdata[, XML doesn't have such a marked section. It's <![CDATA[ (http://www.w3.org/TR/REC-xml/#sec-cdata-sect), in uppercase.

zcorpan
09-12-2006, 01:53 AM
I need to use <![cdata[...]]> to prevent special characters to create a parse error.What special characters? "<" and "&"? You should escape those as &lt; and &amp; respectively. If that's not it, you probably have issues with character encodings, and a CDATA section won't help you there.