xsl-list
[Top] [All Lists]

RE: [xsl] Treat CDATA section content as node

2010-02-25 03:34:00

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

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--