XQuery

XQuery

(pwalmsley@datypic.com)

ISBN: 1491915103

2nd edition, , O'Reilly Media, Inc.

Chapter 13: Inputs and Outputs

Please note that the book contains many inline examples and informal tables that are not provided here.

Example 13-1. Output declarations
xquery version "3.0";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; 
declare namespace prod = "http://datypic.com/prod"; 
declare option output:method "xml"; 
declare option output:indent "yes"; 
declare option output:cdata-section-elements "prod:desc prod:name"; 
declare option output:omit-xml-declaration "yes";
Example 13-2. Specifying the name of a parameters document
xquery version "3.0";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; 
declare option output:parameter-document "parameters.xml";
Example 13-3. Serialization parameters in a separate XML document (parameters.xml)
<output:serialization-parameters
   xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"
   xmlns:prod="http://datypic.com/prod">
  <output:method value="xml"/>
  <output:version value="1.0"/>
  <output:indent value="yes"/>
  <output:cdata-section-elements value="prod:desc prod:name"/>
  <output:use-character-maps>
    <output:character-map character="«" map-string="&lt;%"/>
    <output:character-map character="»" map-string="%&gt;"/>
  </output:use-character-maps>
</output:serialization-parameters>
Example 13-4. Serialization parameters in a map
<xquery version "3.1";
declare namespace prod = "http://datypic.com/prod"; 
let $map := map {
   "method": "xml",
   "version": "1.0",
   "indent": true(),
   "cdata-section-elements": (xs:QName("prod:desc"),xs:QName("prod:name")),
   "use-character-maps": map {
                           "«":"&lt;%",
                           "»":"&gt;%">                         }
}
let $element := <prod:name>Fleece Pullover</prod:name>
return serialize($element,$map)
Datypic XQuery Services