[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: enclose output of transform in CDATA section

Subject: Re: enclose output of transform in CDATA section
From: Armen Martirossian <armmarti@xxxxxxxxx>
Date: Thu, 14 Aug 2003 05:43:55 -0700 (PDT)
generate cdata section with xsl
--- Dave Beattie <Dave.Beattie@xxxxxxxxxxx> wrote:
> Hi
> 
> I have to produce an output file in the following
> format
> 
> <Message>  
> 	<![CDATA[
> 		...xml document as generated from a transform in
> here ...
> 	]]> 
> </Message>
> 
> Any suggestions as to how I go about doing this.
> 
> Thanks
> 
> 
> Dave
>
I can suggest to use xsl:text with
disable-output-escaping="yes", though as discussed
many times the feature(d-o-e) is not supported by all
XSLT processors and must be avoided if possible.

However, to perform an identity transformation for
example, and put the result in the CDATA section, you
can do this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<Message>
			<xsl:text
disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
				<xsl:apply-templates/>
			<xsl:text
disable-output-escaping="yes">]]&gt;</xsl:text>
		</Message>
	</xsl:template>
	
	<xsl:template match="node() | @*">
		<xsl:copy>
			<xsl:apply-templates select="node() | @*"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>


But there is another potential problem here: in spite
of how you output(or generate) CDATA delimiters here,
the source XML can contain "]]>" sequence or even
during the transformation such sequence may be
generated and the result will not be well-formed
XML(CDATA section will contain forbidden "]]>"
sequence)...

Regards,
Armen

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.