Subject: Re: Conditional Transformition for CDATA node
From: "Karl Stubsjoen" <kstubs@xxxxxxxxx>
Date: Sat, 8 Dec 2007 21:52:13 -0700
|
Well then, I guess in this case it's ok to cheat:
<data has_cdata="True">
-or-
<cdata><![CDATA[ .. ]]</cdata>
The apply-templates and match is cleaner in the first example, I'll go
with that!
Karl..
On Dec 8, 2007 9:34 PM, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
> At 2007-12-08 20:43 -0700, Karl Stubsjoen wrote:
> >Can you write a match for an element containing CDATA?
>
> No ... CDATA boundaries are not preserved in the XPath data
> model. CDATA sections are just syntactic sugar and as such are not
> distinguished in the XML Information Set (see Appendix D):
>
> http://www.w3.org/TR/2004/REC-xml-infoset-20040204
>
> >The thought
> >is: raw web content in a CDATA element, and some web content will be
> >well formed. So I might have something like:
> >
> ><root>
> > <data>
> > <div>foo bar<br/>foo bar</div><!-- well formed -->
> > </data>
> > <data><![DATA[
> > <p>not so foo<br>barf<!-- not well formed -->
> > ]>
> > </data>
> ></root>
> >
> >In one case, I'd simply xsl:value-of the data element, and in the
> >other case, I'd write an identity transformation for it.
>
> Just by using the identity transform you will get the identical
> *information* in the result tree as in the source, you just won't get
> the identical syntax for that information.
>
> A downstream application based on the XML information set will not
> see a difference if the characters of your CDATA section are instead
> individually escaped.
>
> I hope this helps.
>
> . . . . . . . . . . . Ken
>
> --
> Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
> World-wide corporate, govt. & user group XML, XSL and UBL training
> RSS feeds: publicly-available developer resources and training
> G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
> Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
> Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
> Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
> Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|