Some time you may need to wrap text node in a CDATA section as part of your XQuery development. For example say you need to generate the following document
<?xml version="1.0" encoding="UTF-8"?>
<sf:Resource xmlns:sf="http://www.canadapost.ca/smartflow" contentID="PAYMENT">
<![CDATA[
<payment-data>
<account-number>bar</account-number>
<total-due>bar</total-due>
<due-date>bar</due-date>
</payment-data>
]]></sf:Resource>
The following query makes use of a processor specific XQuery option called ddtek:serialize
Notice the syntax to define an expanded QName with namespace is { {uri} local-name } which is different from what is erroneously described in the XQuery Tips & Tricks
The second takeaway is how the content inside sf:Resource needs to be escaped text to produce the required result
declare namespace sf="http://www.canadapost.ca/smartflow";
declare option ddtek:serialize
"omit-xml-declaration=no,encoding=UTF-8,indent=yes,cdata-section-elements={{http://www.canadapost.ca/smartflow}Resource}";
declare variable $foo := "bar";
<sf:Resource contentID="PAYMENT">
<payment-data>
<account-number>{ $foo }</account-number>
<total-due>{ $foo }</total-due>
<due-date>{ $foo }</due-date>
</payment-data>
</sf:Resource>
Multiple CDATA sections are declared using ; as separator
cdata-section-elements="{{http://www.canadapost.ca/smartflow}Resource};{{http://www.canadapost.ca/smartflow}Foo}"