Re: [xsl] CDATA back to its original shape

Subject: Re: [xsl] CDATA back to its original shape
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 13:52:16 +0000
Hi Ruben,

>>If you said _why_ you wanted to use CDATA marked sections someone may
>>suggest what approach you should take, but note that CDATA sections are
>>just a authoring shortcut to avoid writing lots of &lt; unline elements
>>or attributes they have no effect on the actual result of the parse in
>>the XPath tree model of an XML document.
> The reason is that I would like my XML document to store information
> about, among other things, flash objects, like this one:


> ... and instead of going through all the tags inside the OBJECT I
> thought it could be done in an easier way with CDATA enclosing
> everything.

If you have your flash object definition tucked up inside a CDATA
section, then the only way to get it out and make it make any kind of
HTML sense is to use disable-output-escaping:

  <xsl:value-of select="my_object" disable-output-escaping="yes" />

If you have the flash object definition as XML within the 'my_object'
element, then you can copy it into the HTML output with:

  <xsl:copy-of select="my_object/node()" />

This is not only shorter, but it also has the advantage that if in
future you want to, say, add parameters to every OBJECT you're
outputting, you could do so from within your XSLT without touching the
source XML. Because the object definition is XML, you can manipulate
it as XML.

The disadvantage with this approach, which might hit in your case and
certainly applies to the example that you gave, is that the content of
my_object has to be well-formed XML, which means that unless the flash
object definition is XHTML (all elements are closed, empty elements
are closed with '/>', attributes have quotes around them and so on)
then you'll get an non-well-formed source document, which you won't be
able to do anything with. Personally, I'd use Tidy or something to
smarten it up and then use it as XML, but that may be too costly in
your case.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread