CDATA in XML Transform

Posted by sedge on 06-Jan-2011 02:58

Sonic 8.0.1

I have an XML Message Part that I need to delimit with CDATA and wrap in two layers of XML. I have a fairly simple stylesheet that looks like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ic="http://tempuri.org/IC45101/IC45101">
    <xsl:output method="xml" omit-xml-declaration="yes" cdata-section-elements="xx:s"
            xmlns:xx="http://tempuri.org/IC45101/IC45101"/>
    <xsl:template match="/">
        <xsl:element name="UpdateStallReserveInfo" namespace="http://tempuri.org/IC45101/IC45101">
            <xsl:element name="s" namespace="http://tempuri.org/IC45101/IC45101">
                <xsl:copy-of select=".">
                </xsl:copy-of>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

The output I get is:

<UpdateStallReserveInfo xmlns="http://tempuri.org/IC45101/IC45101">
    <s>
       ... the Message Part ...
    </s>
</UpdateStallReserveInfo>

And what I need is:

<UpdateStallReserveInfo xmlns="http://tempuri.org/IC45101/IC45101">
    <s>
       <![CDATA[... the Message Part ...]]>
    </s>
</UpdateStallReserveInfo>

How can I get the CDATA delimiters?

All Replies

Posted by sk185050 on 06-Jan-2011 05:02

I tried with

                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                xmlns:ic="http://tempuri.org/IC45101/IC45101">

   

   

       

           

               

           

       

   

And XMl

   

       

            3

           

       

   

Got this

       

           

                ]]>

            

                   

                           3

                          

                   

            

     

            ]]>

       

This is what you are expecting?

Posted by sedge on 10-Jan-2011 23:25

What did you run with?


I ran:



        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ic="http://tempuri.org/IC45101/IC45101">
   
            xmlns:xx="http://tempuri.org/IC45101/IC45101"/>
   
        http://tempuri.org/IC45101/IC45101">
            http://tempuri.org/IC45101/IC45101">
               
               
           
       
   

with:


   
       
            3
           
       
   

In:
- Sonic Workbench 8.0.1 as a scenario
- XMLSpy 2011

and got the same results:

http://tempuri.org/IC45101/IC45101">

 
  
   
     3
    
   
  
 

No CDATA!

It appears that cdata-section-elements are ignored if they contain valid XML. I can't figure out why that would be the case.
When I ran the sample here (http://code.activestate.com/lists/perl-xml/4444/) it worked OK until I added child XML elements. If I just added a child string it was wrapped in CDATA correctly.

Posted by sk185050 on 11-Jan-2011 00:42

I ran with sonic 7.5.1 using the standard sonic transformation service.

Posted by sedge on 16-Feb-2011 17:22

Here's the solution (from Progress support)...

xmlns:xsl=http://www.w3.org/1999/XSL/Transform>

     xmlns:xx="http://tempuri.org/IC45101/IC45101"/>

    

         

              

                    &lt;![CDATA[

                   

                    ]]&gt;

              

         

    

This thread is closed