Karthick,
 
Section 20.2 of the XSLT 2.0 specification states:
 
If output escaping is disabled for text within an element that would normally be output using a CDATA section, because the element is listed in the cdata-section-elements, then the relevant text will not be included in a CDATA section. In effect, CDATA is treated as an alternative escaping mechanism, which is disabled by the disable-output-escaping option.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Karthick Sankarachary [mailto:karthick.sankarachary@gmail.com]
Sent: 29 May 2009 21:25
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: [saxon] CDATA sections in XSL Outputs

Hello,

It looks like the "cdata-section-elements" attribute of the <xsl:output> element does not behave as expected in Saxon 9.1.0.6.

As per the spec, that attribute "specifies a list of the names of elements whose text node children should be output using CDATA sections".

This could very well be just a regression, given that this most likely used to work in Saxon 8.7. For your convenience, a test case has been included below:

import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.io.Writer;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import junit.framework.TestCase;

import org.junit.Test;

public class XslTest extends TestCase {
   
    @Test public void testXsl() throws Exception {
       
        TransformerFactory tfactory = TransformerFactory.newInstance();

        String source = "<?xml version='1.0' encoding='UTF-8'?><tns:inputXML xmlns:tns='http://www.example.org/tns'><tns:texteLibre><![CDATA[Paragraphs are represented by <p>.]]></tns:texteLibre></tns:inputXML>";
        String xsl = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:tns='http://www.example.org/tns' version='2.0'><xsl:output method='xml' encoding='ISO-8859-1' indent='yes' cdata-section-elements='observation'/><xsl:template match='/'><fluxXML><xsl:element name='observation'><xsl:value-of disable-output-escaping='yes' select='//tns:texteLibre'/></xsl:element></fluxXML></xsl:template></xsl:stylesheet>";
        Transformer transformer =
            tfactory.newTransformer(new StreamSource(new ByteArrayInputStream(xsl.getBytes())));
       
        Writer writer = new StringWriter();
        transformer.transform(new StreamSource(new ByteArrayInputStream(source.getBytes())),
                              new StreamResult(writer));

        System.out.println("The result of the transformation is shown below:\n" + writer.toString());
        assertTrue("The result does not contain any cdata sections", writer.toString().contains("<![CDATA["));       
    }

}

Best Regards,
Karthick Sankarachary