468,249 Members | 1,512 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

cdata-section-elements being ignored?

Hello,

Just wondering if anyone could shed any light on this, it's probably me just
being silly...

I have a dataset that I've used to create an XmlDataDocument, in order to
apply XSL. The XSL reformats the XML to another format (still XML, not HTML).
This works fine, but whatever I do, I can't get the finally output section to
have CDATA elements. I've added a cdata-section-elements tag into the xsl
file, but it doesn't seem to have any effect on the output elements. I know
that the xsl:output section is being read, as when I put in an
omit-xml-declaration into it, it has the correct effect.

I know that CDATA sections aren't normally strictly necessary (or even
desirable in some cases), but the software I'm integrating with requires them
to be in place.

This is the section of code that applies the XSL:
XmlDataDocument xmlDoc = new XmlDataDocument(ds);XslCompiledTransform xslt =
new
XslCompiledTransform();xslt.Load(Server.MapPath("x sl/routes.xsl"));XmlWriterSettings
ws = xslt.OutputSettings.Clone();//xslt.Transform(xmlDoc,
XmlWriter.Create(Response.Output, ws));
xslt.Transform(xmlDoc, null, Response.Output ); Here is the XSL that is
supposed to have the elements output within CDATA sections:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output
method="xml" omit-xml-declaration="yes"

cdata-section-elements="name cmt sym type"
/>
<xsl:template match="/"> <gpx version="1.1" creator="Blah"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"> <xsl:for-each
select="routes/route"> <wpt> <xsl:attribute name="lat">
<xsl:value-of select="lat" /> </xsl:attribute> <xsl:attribute
name="lon"> <xsl:value-of select="lon" /> </xsl:attribute>
<name> <xsl:value-of select="name"/> </name>
<cmt></cmt> <sym> <xsl:value-of select="symbol" />
</sym> <type> <xsl:value-of select="type"/> </type>
</wpt> </xsl:for-each> </gpx></xsl:template></xsl:stylesheet>
And here is the resolutely non CDATA output

<gpx version="1.1" creator="Blah"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wpt lat="81.367820"
lon="-65.740822"><name>Name</name><cmt>abcd</cmt><sym>abcd</sym><type>text
field</type></wpt></gpx>
I know the current output data doesn't require it, but what I'm after is
output like:

<gpx version="1.1" creator="Blah"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<wpt lat="81.367820" lon="-65.740822">
<name>![CDATA[Name]]></name>
<cmt>![CDATA[abcd]]></cmt>
<sym>![CDATA[abcd]]></sym>
<type>![CDATA[text field]]></type>
</wpt>
</gpx>

I hope it's just me being stupid, but I'd be very grateful for any suggestions

Thanks
Steverino

Jun 16 '06 #1
2 4854
* Steveino wrote in microsoft.public.dotnet.xml:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output
method="xml" omit-xml-declaration="yes"

cdata-section-elements="name cmt sym type"


It seems the problem is that there is not actually a name or cmt
element, but {'http://www.topografix.com/GPX/1/1', 'name'}, etc.
elements. You have to declare a prefix for the namespace and use
the prefix in the attribute, so

<xsl:output xmlns:gpx = 'http://www.topografix.com/GPX/1/1'
cdata-section-elements="gpx:name gpx:cmt ..."

would be closer.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 16 '06 #2

"Bjoern Hoehrmann" wrote
It seems the problem is that there is not actually a name or cmt
element, but {'http://www.topografix.com/GPX/1/1', 'name'}, etc.
elements. You have to declare a prefix for the namespace and use
the prefix in the attribute, so

<xsl:output xmlns:gpx = 'http://www.topografix.com/GPX/1/1'
cdata-section-elements="gpx:name gpx:cmt ..."

would be closer.


Bjoern, thank you very much for your help, you've solved it completely.

I'm still experimenting with this stuff - I hadn't realised that the xsl
matched based on the namespace as well. Of course it makes sense now you've
pointed it out.

Thanks,
Steveino
Jun 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by indo3 | last post: by
3 posts views Thread by Balaras | last post: by
10 posts views Thread by Simon Brooke | last post: by
4 posts views Thread by kplkumar | last post: by
12 posts views Thread by Peter Michaux | last post: by
3 posts views Thread by yawnmoth | last post: by
7 posts views Thread by Silfheed | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.