[thelist] XSLT: escaping CDATA

Keith Gaughan keith at digital-crew.com
Wed Apr 27 12:23:53 CDT 2005

Bob & Kelly Crispen - Web Builders' Toolkit wrote:

> I've got a little XSLT ruleset that converts XBEL to XHTML at 
> <http://www.crispen.org/sync/rr.xsl.txt>.  I drive it via PHP at 
> <http://www.crispen.org/sync/rr-bookmarks.txt> and the result is 
> <http://www.crispen.org/sync/>.
> The problem is, I've got a CDATA section in the XSLT script, but the 
> XSLT processor consumes it (good thing, since the CSS it wraps doesn't 
> look anything like XML) so that I'm left with
>     <style type="text/css">
>       /**/
> and
>       /* */
>     </style>
> Is there any way to escape the CDATA?  CDATA sections can't be nested 
> unless I'm totally misreading things.
> Any ideas?

Simple: Don't bother with them. No really, don't. I can't emphasise this

<tip title="CDATA sections aren't special">
There is nothing, and I mean nothing, about CDATA sections that
distinguishes them from regular text, no logical difference between




None. CDATA was meant as a shortcut for people writing XML docs by
hand and nothing more. Your best bet is to just spit out whatever
you want and make sure it's properly encoded, which it ought to be

BTW, in case anybody thinks I'm talking through my hat, take a read
of what Tim Bray has to say on the matter[1] in his Annoted XML
Specification[2] in section 2.7 (first technical explaination). And
if that doesn't convince you, take a read of Ned Batchelder's

[1] http://www.xml.com/axml/notes/CDsects.html
[2] http://www.xml.com/axml/testaxml.htm
[3] http://www.nedbatchelder.com/blog/20040908T082607.html


More information about the thelist mailing list