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:
When called within an XSLT stylesheet, the second argument may be the name of an
xsl:output
element in the stylesheet, written as a string literal (it must be a literal,
or at any rate, an expression that is evaluated at compile time).
In non-XSLT environments, the second argument may be the name of the output method (xml, html, xhtml, text), written as a string literal. In this case the other serialization parameters are defaulted.
In all environments, the second argument may be an xsl:output
element
conforming to the rules defined in the XSLT specification. This element may be constructed
dynamically, and may therefore be used to decide all the serialization properties dynamically.
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.