[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: enclose output of transform in CDATA section
--- 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"><![CDATA[</xsl:text> <xsl:apply-templates/> <xsl:text disable-output-escaping="yes">]]></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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|