473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 5219
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: indo3 | last post by:
I know one can define CDATA text by <!]> which is the same as PCDATA: &lt;bla&gt; &amp;bla; But if you define an attribute in a DTD
3
by: Balaras | last post by:
Hi, Can sombody here please help me a bit with a regular expression. I have a xml file where I need to strip the CDATA sections of any contained data. Eg. <xml> <tag><]></tag>...
4
by: Jake Barnes | last post by:
I'm reading over this page: http://wiki.script.aculo.us/scriptaculous/show/Usage I'm struck by this code example +++++++++++++++++++++++++++++++ 3. Use
10
by: Simon Brooke | last post by:
Here's my problem: <xsl:template match="/category"> .... <script type="text/javascript"> &lt;!]&gt; </script> .... </xsl:template>
4
by: kplkumar | last post by:
After serialzing I want, <MyRequest> <Content SigningScheme="pkcs7"><!]></Content> </MyRequest> _________________________________________________________________________________________ ...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
3
by: yawnmoth | last post by:
How might I go about including a ]]in a cdata tag? Since ]]>'s normally close cdata's, ]]>, by itself, wouldn't work...
0
by: anilnagthane | last post by:
Following is the xml which i want to convert in cdata format <Root> <Start> <One>Some Data 1</One> <Two>Some Data 1</Two> <Three>Some Data 1</Three> ...
7
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.