[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can't output CDATA section

Subject: Re: Can't output CDATA section
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 7 Jul 2004 15:49:43 +0100
cdata javascript
Hi Robert,

> How can I get the content of the CDATA section of this node?
>
> <option3link><![CDATA[javascript:objDialogBox.dlgReset();moduleFocus=old
> ModuleFocus;]]></option3link>
>
> The use of
>
> <xsl:value-of select="option3link"/>
> or
> <xsl:copy-of select="option3link/."/>
>
> doesn't work?

You don't say, but I suspect that you want the output to look like:

  <output><![CDATA[javascript:objDialogBox.dlgReset();moduleFocus=oldModuleFocus;]]></output>

and are frustrated because you're instead getting:

  <output>javascript:objDialogBox.dlgReset();moduleFocus=oldModuleFocus;</output>

The reason you're getting this output is that XSLT doesn't keep track
of which text appears within a CDATA section and which text doesn't.
As far as XSLT is concerned, your <option3link> element above is
*exactly* the same as:

  <option3link>javascript:objDialogBox.dlgReset();moduleFocus=old
  ModuleFocus;</option3link>

In both cases, you have an <option3link> element which contains a text
node whose value is "javascript:objDialogBox.dlgReset();moduleFocus=old
ModuleFocus;".

Similarly, the result tree that you generate has elements, attributes
and text nodes in it -- there aren't any "CDATA nodes".

But you can get XSLT to output an element's text nodes in CDATA
sections. To do this, use the <xsl:output> element at the top level of
the stylesheet and set the cdata-section-elements attribute to hold
the name(s) of the element(s) that should contain CDATA sections in
the output. For example:

<xsl:output cdata-section-elements="output" />

means that the result of:

  <output>
    <xsl:value-of select="option3link" />
  </output>

will be:

  <output><![CDATA[javascript:objDialogBox.dlgReset();moduleFocus=old
  ModuleFocus;]]></output>

Of course you can name the element in which the CDATA section appears
anything you like -- it doesn't have to be called 'output' -- just
make sure that that's the name you list in the cdata-section-elements
attribute.
  
You might alternatively be able to use disable-output-escaping, but
I'd avoid that method if you can.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.