Hi,

  The instruction xsl:output contains information for the serializer,
would the XSLT processor be in charge of it.  Like in the first case
below.  In the second case, you take the output tree of the
transformation and use it to construct another tree (with the root
element descriptiveText).  So the serializer of the XSLT processor is
never used.  The output tree of the transformation is never serialized
to text, you use it directly in another tree.

  When you manipulate a "piece of XML" in XPath, XQuery or XSLT, you
manipulate a parsed version of it (an instance of XDM).  This is a
tree in memory, and it has forgotten about some non-relevant
properties from the lexical form it was parsed from (if ever), like
whether some text was wrapped in a CDATA section, or the order of the
attributes of one elements.

  So the first question to answer is probably whether why do you need
a CDATA section?  If you really do, then show us a minimal
reproduction of the problem with the options.

  Regards,

-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/


On 7 May 2015 at 09:37, ? wrote:
> 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]
>
> 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
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to