# saxon:serialize()

serialize(node, format)

This function takes two arguments: the first is a node (generally a document or element node) to be serialized. When called within an XSLT stylesheet, the second argument is the name of an `xsl:output` element in the stylesheet. In non-XSLT environments, the second argument is the name of the output method (xml, html, xhtml, text), and the other serialization parameters are defaulted. The second argument must be known at compile time (it will typically be supplied as a string literal.) 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 XSLT stylesheet 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: in XQuery, if more control is required over serialization, it is possible to invoke an XSLT stylesheet that calls `xsl:result-document`. For an example, see saxon:transform().

Next