View Old View New View Both View Only Previous Next

This draft contains only sections that have differences from the version that it modified.

W3C

XSLT and XQuery Serialization 4.0

W3C Editor's Draft 23 February 2026

This version:
https://www.w3.org/TR/2000/REC-xslt-xquery-serialization-40-20000101/
Latest version of XSLT and XQuery Serialization 4.0:
https://www.w3.org/TR/xslt-xquery-serialization-40/
Most recent version of XSLT and XQuery Serialization 4:
https://www.w3.org/TR/xslt-xquery-serialization-4/
Most recent version of XSLT and XQuery Serialization:
https://www.w3.org/TR/xslt-xquery-serialization/
Most recent Recommendation of XSLT and XQuery Serialization:
https://www.w3.org/TR/xslt-xquery-serialization-31/
Editor:
Michael Kay, Saxonica <http://www.saxonica.com/>

This document is also available in these non-normative formats: XML.


Abstract

This document defines methods of serializing an instance of the data model defined in [XDM 4.0] into a sequence of octets, conforming to a variety of formats including XML, HTML, and JSON. Serialization is designed to be a component that can be used either on its own, or invoked from languages such as [XSLT 4.0], [XPath 4.0] or [XQuery 4.0].

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document.

This document is a working draft developed and maintained by a W3C Community Group, the XQuery and XSLT Extensions Community Group unofficially known as QT4CG (where "QT" denotes Query and Transformation). This draft is work in progress and should not be considered either stable or complete. Standard W3C copyright and patent conditions apply.

The community group welcomes comments on the specification. Comments are best submitted as issues on the group's GitHub repository.

The community group maintains two extensive test suites, one oriented to XQuery and XPath, the other to XSLT. These can be found at qt4tests and xslt40-test respectively. New tests, or suggestions for correcting existing tests, are welcome. The test suites include extensive metadata describing the conditions for applicability of each test case as well as the expected results. They do not include any test drivers for executing the tests: each implementation is expected to provide its own test driver.

Dedication

The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).


7 HTML Output Method

Changes in 4.0 (next | previous)

  1. In the HTML and XHTML output methods, the rules for adding and replacing meta elements have been revised to take account of the new HTML5 syntax, for example <meta charset="utf-8">.  [Issue 318 PR 342 14 February 2023]

  2. The default HTML version is now 5. This may result in changes to the serialized output in cases where no explicit HTML version is requested.  [Issue 1889 PR 1977 2 May 2025]

The HTML output method serializes the input tree as HTML.

For example, the following XSL stylesheet generates html output,

<xsl:stylesheet version="2.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0"/>
<xsl:template match="/">
  <html>
    <xsl:apply-templates/>
  </html>
</xsl:template>
...
</xsl:stylesheet>

In the example, the version attribute of the xsl:output element indicates the version of the HTML Recommendation [HTML] to which the serialized result is to conform.

[Definition: The requested HTML version is the value of the html-version serialization parameter if present; otherwise the value of the version serialization parameter if present; otherwise 5.0.]

This document provides the normative definition of serialization for the HTML output method if the requested HTML version has the lexical form of a value of type decimal whose value is 1.0 or greater, but no greater than 5.0. For any other requested HTML version, the behavior is implementation-defined. In that case the implementation-defined behavior may supersede all other requirements of this recommendation.

An implementation is required to behave as specified in this document when the requested version is 5.0. If the requested version is greater than or equal to 1 but less than 5.0, then the processor may behave as if the requested version were 5.0.

It is entirely the responsibility of the supplier of the input tree to ensure that it conforms to the relevant HTML specification. It is not an error if the input tree is invalid HTML. Equally, it is entirely under the control of the supplier of the input tree whether the output conforms to HTML. If the result tree is valid HTML, the serializermust serialize the result in a way that conforms with the requested HTML version.

7.4 Writing Comments and Processing Instructions

Changes in 4.0 (next | previous)

  1. The way processing instructions are handled when generating HTML5 has changed, reflecting the fact that HTML5 no longer recognizes processing instructions.  [Issue 2344 PR 2372 20 January 2026]

Comment nodes are written as HTML comments, using the syntax <!--comment-->.

Prior to HTML5, the HTML output method must terminate processing instructions with > rather than ?>. It is a serialization error [err:SERE0015] to use the HTML output method when > appears within a processing instruction in input tree.

With HTML5, a processing instruction must be written as an HTML comment, in the form <!--?targetdata?-->. Here target is the name of the processing instruction, and data is its string value; they are separated by a single space. If the string value of the processing instruction contains two adjacent hyphens, they must be separated in the output by a single space. The space separator is omitted if the string value of the processing instruction is zero-length. For example, the processing instruction <?xml-stylesheet type="text/xsl" href="render.xsl"?> is serialized as <--?xml-stylesheet type="text/xsl" href="render.xsl"?-->