Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2007, 06:26 PM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default CDATA Section using XSLT

Hi All,

I have a xml file as an input to a XSLT file which will generate transformed xml file.but i need to create all transformed Xml in to a CDATA section.

Eg:
input :
<numbers>
<x>2</x>
<y>3</y>
</numbers>

xslt:

<xsl:template match="/numbers">
<xsl:element name="Nums">
<xsl:element name="Num1"><xsl:value-of select="//y" /> </xsl:element>
<xsl:element name="Num2"><xsl:value-of select="//x" /> </xsl:element>
</xsl:element>
</xsl:template>


output Required :
<ACORD>
<![CDATA[

<Nums>
<Num1>3</Num1>
<Num2>2</Num2>
</Nums>

]/>
</ACORD>


Any one could you please help me on this?

Thanks
Misanaka

 
Old March 28th, 2007, 03:47 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

CDATA means character data. When you write

<![CDATA[ <x>3</x> ]]>

you are telling the system "x might look like an element, but it isn't one, it is ordinary character data". This means that to construct such output, you shouldn't create x as an element, you should construct it as text.

The first thing I would say is, are you really obliged to generate this output - because it is a bad design and a bad misuse of XML.

However, there are tricks you can use if you really have to do it, provided that the XML is being serialized using an XSLT serializer (this means it won't work in Firefox, for example). Basically, generate the start and end CDATA markers using d-o-e

<xsl:text disable-output-escaping="yes">&lt;!CDATA[[</xsl:text>

It's a horrible kludge and it would be much better to redesign the output XML format, but it's there to use if you're desperate.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 29th, 2007, 06:53 PM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mr.Michale Kay

I read couple of posts you saying this is bad design.But i dont have a choice. i have to send this to third party accepts the string this way.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a CDATA section; add nodeset to CDATA section kssudhish XSLT 3 January 3rd, 2008 07:13 AM
Problem with the CData Section while using Xslt Vered XSLT 2 September 21st, 2006 11:21 AM
XSD CDATA Section chrisjonmcdonald XML 4 July 12th, 2006 08:15 AM
Load CDATA Section into DataSet monuindia2002 XML 1 April 25th, 2006 05:14 AM
CDATA section kai77 Beginning VB 6 0 October 31st, 2004 04:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.