saxonica.com

saxon:serialize()

saxon:serialize($node as node(), $format as xs:string)

saxon:serialize($node as node(), $format as element(xsl:output))

This function takes two arguments: the first is a node (generally a document or element node) to be serialized. The second argument defines the serialization properties. The second argument takes several possible forms:

For example, the function may be used as follows in XQuery:


declare namespace saxon="http://saxon.sf.net/";
declare namespace xsl="http://www.w3.org/1999/XSL/Transform";

<out>{
let $x := <a><b/><c>content</c><?pi?><!--comment--></a>
return saxon:serialize($x, <xsl:output method="xml" 
                             omit-xml-declaration="yes" 
                             indent="yes" 
                             saxon:indent-spaces="1"/>)
}</out>

The function serializes the specified document, or the subtree rooted at the specified element, according to the parameters specified, and returns the serialized document as a string.

This function is useful where the stylesheet or query wants to manipulate the serialized output, for example by embedding it as CDATA inside another XML document, or prefixing it with a DOCTYPE declaration, or inserting it into a non-XML output file.

Note that because the output is a string, the encoding parameter has no effect on the actual encoding, though it does affect what is written to the XML declaration.

Next