user557060
user557060

Reputation: 137

xsl:output using cdata-section-elements, does not encapsulate the targeted cdata-section-element in CDATA tag

I am trying:

            <!-- Arrive at the target XQuery -->
    <p:processor name="oxf:xslt">
        <p:input name="config">
            <xsl:stylesheet version="2.0">
                <xsl:output method="xml" version="1.0"
encoding="iso-8859-1" indent="yes" cdata-section-elements="text"/>
                <xsl:template match="/">
                    <xsl:variable name="apps" select="doc('input:instance')//APPLICATION"/>                         
                    <jaxrx:query>
                        <text>
xquery version "1.0";

declare namespace fn="http://www.w3.org/2005/xpath-functions";

let $dataSet := <xsl:value-of select="doc('input:request')/request/parameters/parameter[name='dataSet']/value" />
let $databaseName := <xsl:value-of select="/Configuration/XMLDB/Name/text()" />
let $applicationID := <xsl:value-of select="doc('input:request')/request/parameters/parameter[name='applicationID']/value" />

let $finalURL := fn:concat($databaseName, "/",$dataSet)
let $applicationsModified := '<xsl:copy-of select="$apps"/>'
                            <!-- disable-output-escaping not supported by Orbeon xslt processor
(: let $applicationsModified := '<xsl:text disable-output-escaping="yes">
                                <![CDATA[<]]>
                            </xsl:text>
                            <xsl:text disable-output-escaping="yes">![CDATA[</xsl:text>
                            <xsl:copy-of select="$apps"/>
                            <xsl:text>]]</xsl:text>
                            <xsl:text disable-output-escaping="yes">
                                <![CDATA[>]]></xsl:text>' :) -->
for $all in fn:collection($finalURL)
    for $anApp in $all/APPLICATION[APPLICATION_ID=$applicationID]
return 
(
replace node $anApp with $applicationsModified
)
                        </text>
                    </jaxrx:query>
                </xsl:template>
            </xsl:stylesheet>
        </p:input>
        <p:input name="data" href="#configuration"/>
        <p:input name="request" href="#request"/>
        <p:input name="instance" href="#instance"/>
        <p:output name="data" id="TargetXQuery"/>
    </p:processor>

With the hope of producing a result like

<jaxrx:query><text><![CDATA[text of xquery with embedded xml]]></text></jaxrx:query>

But the text (name of element) element's textual content does not get encapsulated in a CDATA section. Any pointers why?

I have also tried setting cdata-section-elements="jaxrx:text" instead of cdata-section-elements="text", but I still get

<text>text of xquery with embedded xml</text>

, so no encapsulation in a CDATA section...

Upvotes: 1

Views: 1247

Answers (1)

avernet
avernet

Reputation: 31753

The CDATA sections are not preserved as-is in a pipeline. However, the equivalent XML InfoSet is preserved. So for instance, if you escape an ampersand character using a CDATA section:

<![CDATA[&]]>

When this goes through a pipeline, you might end up with the ampersand escaped differently, as in:

 &amp;

If you need to embed XQuery as text in an XML element, feel free to write something like the following in your pipeline:

<jaxrx:query><text><![CDATA[text of xquery with embedded xml]]></text></jaxrx:query>

If you output this with a "debug" attribute, you won't see the CDATA, but your XQuery will be properly escaped.

Upvotes: 2

Related Questions