[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] output a literal CDATA section


Subject: Re: [xsl] output a literal CDATA section
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 20 Jul 2005 14:37:00 -0400

Dear Georges,

Mike already told you that if your needs aren't addressed by cdata-section-elements, you are out of luck in XSLT 1.0. But I'm piqued by your explanation that you need a CDATA section "because I need to edit the output later on". Maybe there's something you aren't telling us, but are you sure you need them? People edit their XML all the time without its text being marked with CDATA sections. Indeed, CDATA marked sections themselves are nothing but syntax sugar for code that would otherwise have to be escaped character by character to prevent it from being parsed as XML (CDATA basically marks a block of escaped content).

If you could be more explicit about your requirement and the rationales for it maybe we can help a bit more. Often things like this can be dealt with in a post-processing pass. If you don't know the names of the elements in advance ... what do you know about them?

From your example, it appears to me that you could use cdata-section-elements on <programlisting>, but what you want to output the <areaentry> child and its descendants is not copy-of, but xml-writing templates (since this stuff isn't actually to be written as XML, but as escaped XML -- it's "pseudo-XML" hiding in your document).

This kind of output is sometimes called "verbatim XML" or "XML as a string" -- look at http://xmlportfolio.com/xml-to-string/ for a nice, fully-worked-out example of this.

Cheers,
Wendell

At 12:23 PM 7/20/2005, you wrote:
Hi,

I need to output a literal <![CDATA[]]> section via xslt, because I need to edit the output later on. My code (could) look as follows

<xsl:for-each select="exsl:node-set($non-common-params)/complexParam" xml:space="preserve">
<programlisting width="80"><varname><xsl:value-of select="name(./*)"/></varname>
<![CDATA[
<xsl:copy-of select="./*"/>
]]></programlisting>
</xsl:for-each>


Will say, I need the output the following way

         <programlisting width="80"><varname>areaEntry</varname>
         <![CDATA[<areaEntry>
         <id>502147</id>
         <name>Aircraft</name>
       </areaEntry>
         ]]></programlisting>

How can I accomplish that? Using the attribute "cdata-section-elements" is not possible, because I don't know the names of the tags in advance.

Thanks for the help,
Georges


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


Current Thread
Keywords