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 January 3rd, 2008, 06:38 AM
Registered User
 
Join Date: Dec 2007
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default Add a CDATA section; add nodeset to CDATA section

Hi,

 I am trying to add a CDATA section to output and also inside the CDATA section i need to put the node set in the current context. I gave cdata-section-elements in the xsl:output element. Basically i would like to do this -

 <xsl:output method="xml" cdata-section-elements="sampleElm" />
 <xsl:template match="/">
    <sampleElm><![CDATA[<xsl:copy-of select="."]]></sampleElm>
 </xsl:template>

 As you all see, which will not work. Is there a way to do this?

Thank You in advance,
Sudhish

 
Old January 3rd, 2008, 06:51 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". The purpose of CDATA is to say "anything in here is pure text, even if it looks like markup". Therefore, CDATA cannot contain element nodes, by definition.

If you write

<![CDATA[<xsl:copy-of select="."]]>

in a stylesheet, it is equivalent to writing

&lt;xsl:copy-of select="."

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 3rd, 2008, 06:55 AM
Registered User
 
Join Date: Dec 2007
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Michael,

  Absolutely. I agree with you.. But my requirement is to pass an xml inside xml and as per my understanding, the only choice is to put it inside a CDATA element. I was looking for a way to instruct the processor to read a variable or copy a node set.

Thanks,
sudhish

 
Old January 3rd, 2008, 07:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In the XSLT/XPath data model there is no such thing as a CDATA node. The serializer can represent a text node as a CDATA section in the output, but it can't wrap CDATA delimiters around other kinds of node. If you need to generate this kind of structure (and sadly, people who don't understand XML very well often do design such things), then you'll have to step outside the language. One way to do it is to use an extension function such as saxon:serialize() to convert your inner document to a string of lexical XML, and then output this string as a text node using cdata-section-elements to wrap the CDATA delimiters around it. Another way is to generate the CDATA delimiters using disable-output-escaping (or in 2.0 using character maps). It's all a bit dirty - a consequence of poor XML design.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
CDATA Section using XSLT misanaka XSLT 2 March 29th, 2007 06:53 PM
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.