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