Hi Mary,


                Thanks for your response, but even after adding the prolog, the 
CDATA is not added to the elements. When we view the result xml, "<![CDATA[ 
]]>" is not visible to the <text> or <p> element.




                I tried to use xslt transformation to add the CDATA to  the xml 
file. When we use the xslt to some XML structure, it is working fine. But when 
we wrap the xslt transformed content within some element, then the CDATA is 
wiping off (or it is invisible).

Note: Our xquery module where we are trying to add the prolog / xslt is a 
library module, will it cause any impact of CDATA if we use in main  / library 
module.

Please suggest.

Note: we have specified to add the CDATA to all the <p> tag as highlighted 
below.

XSLT Approach: (XSLT without wrapper element)

let $xslt :=
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="2.0">
        <xsl:output method="xml" cdata-section-elements="p"/>
        <xsl:template match="@*|node()">
          <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
        </xsl:template>
      </xsl:stylesheet>
let $outputNode :=
  <description>
    <type>product_description</type>
    <text>
    <p>Pokemon the Movie:</p>
    </text>
  </description>

return
  xdmp:xslt-eval($xslt, $outputNode)/element()

Output:

                <description>
<type>product_description</type>
<text>
<p><![CDATA[Pokemon the Movie:]]></p>
</text>
</description>

XSLT Approach: (XSLT with wrapper element "descriptiveText")

let $xslt :=
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="2.0">
        <xsl:output method="xml" cdata-section-elements="p"/>
        <xsl:template match="@*|node()">
          <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
        </xsl:template>
      </xsl:stylesheet>
let $outputNode :=
  <description>
    <type>product_description</type>
    <text>
    <p>Pokemon the Movie:</p>
    </text>
  </description>

return
<descriptiveText>{
xdmp:xslt-eval($xslt, $outputNode)/element()
}</descriptiveText>

Output:

<descriptiveText>
<description>
<type>product_description</type>
<text>
<p>Pokemon the Movie:</p>
</text>
</description>
</descriptiveText>









Thanks & Regards,

Santhosh

WB MarkLogic Application Support

Mobile:+91-9600025142 | VNET: 468645



-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Mary Holstege
Sent: Tuesday, May 05, 2015 7:11 PM
To: [email protected]
Subject: Re: [MarkLogic Dev General] How to add CDATA to xml content - reg.,





If you really want CDATA escaping for certain elements, you can use the output 
options to control this.



See https://docs.marklogic.com/guide/app-dev/appserver-control#id_86940

for how to set output options at the appserver level and

https://docs.marklogic.com/guide/xquery/langoverview#id_71572 for how to do so 
on a query by query level using prolog options.



In your case, putting this at the top of your query should do it:



declare option xdmp:output "cdata-section-elements=text";



Note, however, that testing this via QConsole won't be effective, because of 
the way QConsole works, its own serialization options will win out.



//Mary



On 05/05/2015 04:42 AM, Florent Georges wrote:

>    Hi,

>

>    First I guess your question has nothing to do with the email you quote.

>

>    You need to ask the question why you need CDATA.  You most likely

> do not.  Why is the following result not good for you?

>

>      <text>&lt;p&gt;Sample content of a P element.&lt;/p&gt;</text>

>

>    Regards,

>

_______________________________________________

General mailing list

[email protected]<mailto:[email protected]>

Manage your subscription at:

http://developer.marklogic.com/mailman/listinfo/general

This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
If you are not the intended recipient(s), please reply to the sender and 
destroy all copies of the original message. Any unauthorized review, use, 
disclosure, dissemination, forwarding, printing or copying of this email, 
and/or any action taken in reliance on the contents of this e-mail is strictly 
prohibited and may be unlawful. Where permitted by applicable law, this e-mail 
and other e-mail communications sent to and from Cognizant e-mail addresses may 
be monitored.
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to