SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
The XPath API
Saxon on .NET
Extensibility
Saxon Extensions
| Introduction
| EXSLT Extensions
| Extension attributes (XSLT only)
| Additional serialization parameters
» | Extension functions
| Extension instructions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# 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