RE: [xsl] Treat CDATA section content as node

Subject: RE: [xsl] Treat CDATA section content as node
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 25 Feb 2010 09:33:38 -0000
> So you might have:
> <xyz><![CDATA[<p>a paragraph</p><p>a paragraph</p><p>a 
> paragraph</p>]]></xyz>
> Maybe I want to tranlsate the <p> tags into <div> tags.

Well, there aren't any <p> tags. That's what CDATA means: "the stuff in here
might look like markup, but it isn't, it's ordinary character data". "<p>"
is therefore not a tag, it's a sequence of three characters. If the author
wanted it to be treated as markup, he shouldn't have put CDATA around it.

Unfortunately this misuse of CDATA is very common. The only way to deal with
it is to extract the string inside the CDATA (as a string) and then pass it
to an XML parser to convert into a tree that XSLT can process. That needs
calls to extension functions (unless you want to do the parsing in XSLT, of
course, which isn't likely to be much fun in XSLT 1.0).


Michael Kay 

Current Thread