472,962 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,962 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 5173
* 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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.