Re: [xsl] CDATA elements in XSLT

Subject: Re: [xsl] CDATA elements in XSLT
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 25 May 2004 13:50:53 -0400
At 2004-05-25 17:45 +0000, Dario Romero wrote:
I am using a xslt transformation on an xml file which has this structure
(... this is only a subset):

xml file:
<AllWells>
 <Wells>
   <WellID>200-100</WellID>
   <PoolName>America &amp; Brownie</PoolName>
 </Wells>
 <Wells>
   <WellID>200-110</WellID>
   <PoolName>Jiraffe &amp; Breton</PoolName>
 </Wells>
</AllWells>

xslt file:
.......
<xsl:template match="Wells">
 <element no_chars="?">
   <xsl:value-of select="PoolName/text()"/>
 </element>
</xsl:template>

The question is; How can I escape the & sign from the xml file to the xml
output so I can write to the xml output: "America & Brownie" instead of
having: "America &amp; Brownie".

But it is already escaped such that a receiving application using an XML processor "sees" the ampersand as an ampersand.


I also need to count on the number of characters for "America & Brownie" and
not from "America &amp; Brownie".

Using the count() function counts the characters, not the markup, so you would get the answer 17 and not 21 for "America &amp; Brownie".


I have read about CDATA but doesn't seems to be the better solution. Could
someone give me some advise on this ? Thank you.

You are confusing what you see from what the application sees. You and I see markup, the applications see characters after the markup has been processed by the XML-aware application utilizing an XML processor.


You probably don't have any problems at all and just think you have problems because you are seeing the markup.

Another example, the count(x) function returns 4 for:

<x>AT&amp;T</x>

I hope this helps.

.................... Ken

--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Next: 3-day XSLT/XPath; 2-day XSL-FO - Birmingham, UK June 14,2004

World-wide on-site corporate, govt. & user group XML/XSL 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 Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread