<spec xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" id="spec-top" w3c-doctype="rec" status="int-review"><header id="spec-header"><title>XSLT and XQuery Serialization 4.0</title><version/><w3c-designation>REC-xslt-xquery-serialization-40</w3c-designation><w3c-doctype>W3C Editor's Draft</w3c-doctype><pubdate><day>28</day><month>January</month><year>2026</year></pubdate><publoc>
    <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://qt4cg.org/2026-01-28/xslt-xquery-serialization-40/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">https://qt4cg.org/2026-01-28/xslt-xquery-serialization-40/</loc>
  </publoc><!-- These altlocs URIs are computed from the concatenation of doc.public, doc.shortname, and either '.xml' or
     '-diff-from-yyyymmdd.html', where 'yyyymmdd' is the earlier version of the spec from which a diff has been produced --><altlocs><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://qt4cg.org/2026-01-28/xslt-xquery-serialization-40/xslt-xquery-serialization-40.xml" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML</loc></altlocs><!-- The latestloc URI is computed from doc.latestloc --><latestloc doc="XSLT and XQuery Serialization 4.0">
    <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://qt4cg.org/specifications/xslt-xquery-serialization-40/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">https://qt4cg.org/specifications/xslt-xquery-serialization-40/</loc>
  </latestloc><!-- These prevlocs URIs are always hard-coded and are never computed from entities --><!--<prevlocs doc="&language;">
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://www.w3.org/TR/2017/PR-xslt-xquery-serialization-31-20170117/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">https://www.w3.org/TR/2017/PR-xslt-xquery-serialization-31-20170117/</loc>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://www.w3.org/TR/2016/CR-xslt-xquery-serialization-31-20161213/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">https://www.w3.org/TR/2016/CR-xslt-xquery-serialization-31-20161213/</loc>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://www.w3.org/TR/2015/CR-xslt-xquery-serialization-31-20151217/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">https://www.w3.org/TR/2015/CR-xslt-xquery-serialization-31-20151217/</loc>
  </prevlocs>
  <latestloc-major doc="&language-major;">
    <loc href="&doc.latestloc-major;">&doc.latestloc-major;</loc>
  </latestloc-major>
  <latestloc-tech doc="&language-tech;">
    <loc href="&doc.latestloc-tech;">&doc.latestloc-tech;</loc>
  </latestloc-tech>
--><prevrec doc="XSLT and XQuery Serialization">
    <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://www.w3.org/TR/xslt-xquery-serialization-31/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">https://www.w3.org/TR/xslt-xquery-serialization-31/</loc>
  </prevrec><!-- <authlist>
    <author>
      <name>Andrew Coleman</name>
      <affiliation>IBM Hursley Laboratories</affiliation>
      <email href="mailto:andrew_coleman@uk.ibm.com">andrew_coleman@uk.ibm.com</email>
    </author>
    <author>
      <name>C. M. Sperberg-McQueen</name>
      <affiliation>Black Mesa Technologies</affiliation>
      <email href="http://www.blackmesatech.com/">http://blackmesatech.com/</email>
    </author>
  </authlist>--><!--<errataloc href="https://www.w3.org/XML/2017/qt-errata/xslt-xquery-serialization-40-errata.html" 
    xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink"
  />

  <translationloc 
    href="https://www.w3.org/2003/03/Translations/byTechnology?technology=xslt-xquery-serialization-40"/>
--><authlist><author><name>Michael Kay</name><affiliation>Saxonica</affiliation><email xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.saxonica.com/" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">http://www.saxonica.com/</email></author></authlist><status><p><emph>This section describes the status of this document at the time of its publication.
               Other documents may supersede this document.</emph></p><p>This document is a working draft developed and maintained by a W3C Community
Group, the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://www.w3.org/community/xslt-40/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XQuery and XSLT
Extensions Community Group</loc> 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.</p><p>This draft is a snapshot of the specification representing the consensus of
the Community Group at the time of publication. It is published with a dated URL
and will remain available at that URL so that users and implementors can refer
to this as a versioned draft, confident that it won’t change. However, the work
is not finished, and the specification is under active development. For links to
the most recent specifications, see <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://qt4cg.org/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>.</p><p>The community group welcomes comments on the specification. Comments are best submitted
         as issues on the group's <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://github.com/qt4cg/qtspecs/issues" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">GitHub repository</loc>.</p><p>The community group maintains two extensive test suites, 
            one oriented to XQuery and XPath, the other to XSLT.
         These can be found at <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://github.com/qt4cg/qt4tests" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">qt4tests</loc> and
         <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="https://github.com/qt4cg/xslt40-test" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">xslt40-test</loc> 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.</p><note role="dedication" id="dedication"><p>The publications of this community group 
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="../xquery-40/xpath-40.html#dedication" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">are dedicated</loc> to our co-chair,
Michael Sperberg-McQueen (1954–2024).</p></note></status><abstract><p>This document defines methods of serializing an instance of the data model defined in
     <bibref ref="xpath-datamodel-40"/> 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 <bibref ref="xslt-40"/>, <bibref ref="xpath-40"/> or <bibref ref="xquery-40"/>.</p></abstract><langusage><language id="en">English</language></langusage><revisiondesc><p/></revisiondesc></header><body><div1 id="intro"><head>Introduction</head><changes><change>If a section of this specification has been updated since version 3.1,
        an overview of the changes is provided, along with links to
        navigate to the next or previous change.</change><change>Sections with significant changes are marked with a ✭ symbol in the
        table of contents.</change></changes><p>This document defines methods of serializing the W3C XQuery
and XPath Data Model 4.0 (<bibref ref="xpath-datamodel-40"/>),
  that is, methods of representing instances of the data model
  as strings or octet sequences. This
is the data model used by <bibref ref="xpath-40"/>,
<bibref ref="xslt-40"/>, and
<bibref ref="xquery-40"/>, and any other specifications that reference it.</p><p>In this document, examples and material labeled as <quote>Note</quote> are provided for
explanatory purposes and are not normative. </p><p>Serialization is the process of converting an instance of the
<bibref ref="xpath-datamodel-40"/> into a sequence of octets.</p><p diff="chg" at="2023-11-01"><termdef id="dt-input-value" term="input value">The XDM value supplied as input to the serializer
is referred to as the <term>input value</term>.</termdef> Some serialization methods apply only
to certain types of input value.</p><note><p>Where serialization is used to process the result of an XQuery evaluation or an XSLT transformation,
  the <termref def="dt-input-value"/> of the serializer corresponds to the output from XQuery
  or XSLT.</p></note><p diff="chg" at="2023-11-01"><termdef id="dt-input-tree" term="input tree">In general the output of the serializer
    will represent the items actually present in the input value, together with other items that are reachable
    from these, for example (in the case of nodes) their descendants. The complete set of items that
    are represented in the output of the serializer is referred to (without loss of generality) as the 
    <term>input tree</term>.</termdef></p><div2 id="terminology"><head>Terminology</head><changes><change issue="1337" date="2024-08-02">
        The term <term>atomic value</term> has been replaced by <term>atomic item</term>.
     </change></changes><p>In this specification,
where they are rendered in small capitals,
the words <rfc2119>MUST</rfc2119>, <rfc2119>MUST NOT</rfc2119>,
<rfc2119>SHOULD</rfc2119>, <rfc2119>SHOULD NOT</rfc2119>, <rfc2119>MAY</rfc2119>, 
  <rfc2119>REQUIRED</rfc2119>, and
<rfc2119>RECOMMENDED</rfc2119> are to be interpreted as described in
<bibref ref="RFC2119"/>.</p><p><termdef id="serializer" term="serializer">As is indicated in
<specref ref="conformance"/>, conformance criteria for serialization
are determined by other specifications that refer to this specification.
A <term>serializer</term> is software that implements some or all of the
requirements of this specification in accordance with such conformance
criteria.</termdef>  A serializer is not <rfc2119>REQUIRED</rfc2119> to directly provide a
programming interface that permits a user to set serialization parameters
or to provide an input sequence for serialization.<!--Text inserted by erratum E11 change 1"-->
In this document, material labeled
as "Note" and examples are provided for explanatory purposes and are not
normative.
<!--End of text inserted by erratum E11-->
</p><p>Certain aspects of serialization are described in this specification 
as <termref def="impdef">implementation-defined</termref> 
or <termref def="impdep">implementation-dependent</termref>.</p><p>
<termdef id="impdef" term="implementation-defined"><term>Implementation-defined</term> indicates an
aspect that <rfc2119>MAY</rfc2119> differ between
<termref def="serializer">serializers</termref>, but whose actual
behavior <rfc2119>MUST</rfc2119> be specified either by another specification that sets
conformance criteria for serialization (see <specref ref="conformance"/>)
or in documentation that accompanies the
<termref def="serializer">serializer</termref>.</termdef></p><p>
<termdef id="impdep" term="implementation-dependent"><term>Implementation-dependent</term> indicates an
aspect that <rfc2119>MAY</rfc2119> differ between
<termref def="serializer">serializers</termref>, and whose actual
behavior is not <rfc2119>REQUIRED</rfc2119>  to be specified either by another specification
that sets conformance criteria for serialization (see
<specref ref="conformance"/>) or in documentation that accompanies the
<termref def="serializer">serializer</termref>.</termdef></p><p>
<termdef id="serial-err" term="serialization error">In some instances, the
<termref diff="chg" at="2023-11-01" def="dt-input-tree"/> cannot be successfully converted
into a sequence of octets given the set of serialization parameter
(<specref ref="serparam"/>) values specified.  A
<term>serialization error</term> is said to occur in such an instance.</termdef>
In some cases, a <termref def="serializer">serializer</termref> is
<rfc2119>REQUIRED</rfc2119>  to <term>raise</term> such an error.
What it means to raise a serialization error is determined by the
relevant conformance criteria (<specref ref="conformance"/>) to which
the <termref def="serializer">serializer</termref> conforms.  In other cases,
there is an <termref def="impdef">implementation-defined</termref> choice
between raising a serialization error and performing a recovery action.
Such a recovery action will allow a
<termref def="serializer">serializer</termref> to produce a sequence of
octets that might not fully reflect the usual requirements of the
parameter settings that are in effect.
</p><!-- Start of text added for Bug 8651 (Erratum SE.E17) --><p>
<termdef id="caseless-compare" term="without regard to case">
Where this specification indicates that two strings are to be
compared <term>without regard to case</term>, the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> translate any characters in the range
<char>U+0041</char> through <char>U+005A</char>
inclusive, to the corresponding lower-case letters in the range
<char>U+0061</char> through <char>U+007A</char> only
for the purposes of making the comparison.  The comparison
succeeds if the two strings are the same length and the code
point of each character in the first string is equal to the
code point of the character in the corresponding position in
the second string.</termdef>
</p><!-- End of text added for Bug 8651 (Erratum SE.E17) --><p>Many terms used in this document are defined in the XPath specification 
<bibref ref="xpath-40"/> or the Data Model specification <bibref ref="xpath-datamodel-40"/>. Particular
attention is drawn to the following:</p><ulist><item><p><termdef id="dt-atomization" term="atomize">The term <term>atomization</term> is defined
in <xspecref spec="XP40" ref="id-atomization"/>.</termdef></p></item><item><p><termdef id="dt-node" term="node">The term <term>node</term>
is defined in <xspecref spec="XP40" ref="id-basics"/>. 
There are seven kinds of <termref def="dt-node">nodes</termref> in the data model: document, element, attribute, text, namespace, processing instruction, and comment.</termdef></p></item><item><p><termdef id="dt-sequence" term="sequence">The term <term>sequence</term>
is defined in <xspecref spec="XP40" ref="id-basics"/>. 
A <termref def="dt-sequence">sequence</termref> is an ordered collection of zero or more items.</termdef></p></item><item><p><termdef id="dt-function-item" term="function item">The term
<term>function item</term> is defined in
<xspecref spec="DM40" ref="function-items"/>.</termdef></p></item><item><p><termdef id="dt-map-item" term="map item">The term
<term>map item</term> is defined in
<xspecref spec="DM40" ref="map-items"/>.</termdef></p></item><item><p><termdef id="dt-array-item" term="array item">The term
<term>array item</term> is defined in
<xspecref spec="DM40" ref="array-items"/>.</termdef></p></item><item><p><termdef id="dt-string" term="string">The term
<term>string</term> is defined in
<xspecref spec="DM40" ref="xml-and-xsd-versions"/>.</termdef></p></item><item><p><termdef id="dt-character" term="character">The term
<term>character</term> is defined in
<xspecref spec="DM40" ref="xml-and-xsd-versions"/>.</termdef></p></item><item><p><termdef id="dt-codepoint" term="codepoint">The term
<term>codepoint</term> is defined in
<xspecref spec="DM40" ref="xml-and-xsd-versions"/>.</termdef></p></item><item><p><termdef id="dt-string-value" term="string value">The term <term>string value</term>
is defined in <xspecref spec="DM40" ref="dm-string-value"/>. 
Every <termref def="dt-node">node</termref> has a <termref def="dt-string-value">string value</termref>. For example, the <termref def="dt-string-value">string value</termref>
of an element is the concatenation of the <termref def="dt-string-value">string values</termref> of all its descendant text <termref def="dt-node">nodes</termref>.</termdef></p></item><item><p><termdef id="dt-expanded-qname" term="expanded QName">The term <term>expanded QName</term>
is defined in <xspecref spec="XP40" ref="id-basics"/>. 
An <termref def="dt-expanded-qname">expanded QName</termref> consists of an optional namespace URI and a local name. An <termref def="dt-expanded-qname">expanded QName</termref> also retains its original namespace prefix (if any), to facilitate casting the expanded QName into a string.</termdef></p></item><item><p><termdef id="null-namespace-URI" term="null namespace URI">
An <termref def="dt-expanded-qname">expanded-QName</termref> whose 
namespace part is an empty sequence,
or an element or attribute whose name expands to such 
an <termref def="dt-expanded-qname">expanded-QName</termref>,
is referred to as having a <term>null namespace URI</term></termdef>.</p></item><item><p><termdef id="non-null-namespace-URI" term="non-null namespace URI">An element or attribute that does not have a <termref def="null-namespace-URI">null namespace URI</termref>, is referred to as having a <term>non-null namespace URI</term></termdef>.</p></item><item><p>
<termdef id="whitespace-char" term="whitespace character">A space character,
TAB character, CR character or NL character is referred to as a
<term>whitespace character</term>.</termdef></p></item></ulist><p>Where this specification indicates that an
XSLT instruction is evaluated, the behavior is as specified by
<bibref ref="xslt-40"/>.  Where it indicates that an XQuery expression is
evaluated, the behavior is as specified by <bibref ref="xquery-40"/>.</p></div2><div2 id="namespaces"><head>Namespaces</head><p>This specification refers to several namespaces that affect the process
of serialization.  These are:</p><ulist><item><p><termdef id="output-namespace" term="Output declaration namespace">the
<term>Output declaration namespace</term>,
<code nobreak="false">https://www.w3.org/2010/xslt-xquery-serialization</code></termdef>;</p></item><item><p><termdef id="xml-namespace" term="XML namespace">the
<term>XML namespace</term>,
<code nobreak="false">https://www.w3.org/XML/1998/namespace</code></termdef>;</p></item><item><p><termdef id="xhtml-namespace" term="XHTML namespace">the
<term>XHTML namespace</term> namespace,
<code nobreak="false">https://www.w3.org/1999/xhtml</code></termdef>;</p></item><item><p><termdef id="svg-namespace" term="SVG namespace">the
<term>SVG namespace</term>,
<code nobreak="false">https://www.w3.org/2000/svg</code></termdef>; and</p></item><item><p><termdef id="mathml-namespace" term="MathML namespace">the
<term>MathML namespace</term> namespace,
<code nobreak="false">https://www.w3.org/1998/Math/MathML</code>.</termdef></p></item></ulist><p>Wherever an element node or attribute node is said to be in a
particular namespace, it is understood that the namespace URI of the
node is equal to the namespace URI corresponding to that namespace.
Wherever a namespace node is said to be a namespace node for a
particular namespace, it is understood that the
<termref def="dt-string-value">string value</termref> of the node is
equal to the namespace URI corresponding to that namespace.</p></div2></div1><div1 id="serdm"><head>Sequence Normalization</head><p>The <termref diff="chg" at="2023-11-01" def="dt-input-value"/> is a sequence.
Prior to serializing a sequence using any of
the output methods whose behavior is specified by this document
(<specref ref="serparam"/>), 
with the exception of the JSON and Adaptive
output methods,
the <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> first
compute a normalized sequence for serialization; it
is the normalized sequence that is actually serialized.
<termdef id="sequence-normalization" term="sequence normalization">The purpose of <term>sequence normalization</term> is
to create a sequence that can be serialized as a
well-formed XML document or external general parsed entity, that
also reflects the content of the input sequence to the extent possible.</termdef>
<termdef term="result tree" id="result-tree">The result of the <termref def="sequence-normalization">sequence normalization</termref> process is a <term>result tree</term>.</termdef></p><p>The normalized sequence for serialization is constructed by applying all
  of the following rules in order, with the <termref diff="chg" at="2023-11-01" def="dt-input-value"/> being
input to the first step, and the sequence that results from any
step being used as input to the subsequent step.
For any <termref def="impdef">implementation-defined</termref>
output method, it is <termref def="impdef">implementation-defined</termref>
whether this sequence normalization process takes place.
For the JSON and Adaptive output methods,
sequence normalization <rfc2119>MUST NOT</rfc2119> take place.</p><imp-def-feature>For any <termref def="impdef">implementation-defined</termref>
output method, it is <termref def="impdef">implementation-defined</termref>
whether  <termref def="sequence-normalization">sequence normalization</termref>
process takes place.</imp-def-feature><!--Text replaced by erratum E6 change 1"--><p>Where the process of converting the input sequence
to a normalized sequence indicates that a value <rfc2119>MUST</rfc2119> be cast to
<code role="SCHEMATYPE" nobreak="false">xs:string</code>, that operation is
defined in <xspecref spec="FO40" ref="casting-to-string"/> of
<bibref ref="xpath-functions-40"/>.
Where a
step in the sequence normalization process indicates that a node should be
copied, the copy is performed in the same way as an XSLT
<code nobreak="false">xsl:copy-of</code> instruction that has a
<code nobreak="false">validation</code> attribute whose value is
<code nobreak="false">preserve</code> and has a
<code nobreak="false">select</code> attribute whose effective value is the
node, as described in <xspecref spec="XT40" ref="copy-of"/>
of <bibref ref="xslt-40"/>,
or equivalently in the same way as an XQuery
content expression as described in Step 1e of
<xspecref spec="XQ40" ref="id-content"/>
of <bibref ref="xquery-40"/>, where the construction mode is
<code nobreak="false">preserve</code>.

Let <var>S0</var> be the sequence that is input to serialization. 
The steps in computing the normalized sequence are:
</p><!--End of text replaced by erratum E6--><olist><item><p>Create a new sequence <var>S1</var> from <var>S0</var> as follows. For
each item in <var>S0</var>, if the item is a JNode, copy the <code nobreak="false">·content·</code>
    property of the item; otherwise, copy the item itself.</p></item><item><p>Create a new sequence <var>S2</var> from <var>S1</var> as follows. For
each item in <var>S1</var>, if the item is an array, copy the results of
passing the item into the function <code nobreak="false">array:flatten()</code>; otherwise, copy the item
itself. If <var>S1</var> is empty, let <var>S2</var> consist
of a zero-length string. </p></item><item><p>Create a new sequence <var>S3</var> from <var>S2</var> as follows. For
each item in <var>S3</var>, if the item is atomic, copy to <var>S3</var> only the lexical
representation resulting from casting the item to an <code role="SCHEMATYPE" nobreak="false">xs:string</code>, otherwise, 
copy the item to <var>S3</var>.</p></item><item><p>Create a new sequence <var>S4</var> from <var>S3</var> as follows. If the
<code nobreak="false">item-separator</code> serialization parameter is present, then copy each item in
<var>S3</var> to <var>S4</var>, inserting between each pair of items
a string whose value is equal to the value of the item-separator parameter. If the
<code nobreak="false">item-separator</code> serialization parameter is not present, then first maximally 
group the items in <var>S3</var> into subsequences of <code role="SCHEMATYPE" nobreak="false">xs:string</code> items 
and non-<code role="SCHEMATYPE" nobreak="false">xs:string</code> items. For each group of items, if the group is a subsequence of
non-<code role="SCHEMATYPE" nobreak="false">xs:string</code> items, copy the subsequence to
<var>S4</var>; if the group is a subsequence of <code role="SCHEMATYPE" nobreak="false">xs:string</code> 
items, copy to <var>S4</var> the results of passing to
<code nobreak="false">fn:string-join()</code> the subsequence and the value of
<code nobreak="false">item-separator</code> as the function’s two parameters. </p></item><item><p>Create a new sequence <var>S5</var> from <var>S4</var> as follows.
For each item in <var>S4</var>, if the item is a string,
copy to <var>S5</var> a text node whose <termref def="dt-string-value">string value</termref> is equal to
the string; otherwise, copy the item to <var>S5</var>.</p></item><item><p>
Create a new sequence <var>S6</var> from <var>S5</var> as follows.
For each item in <var>S5</var>, if the item is a document node,
copy its children to <var>S6</var>; otherwise, copy the item to <var>S6</var>.</p></item><item><p>Create a new sequence <var>S7</var> from <var>S6</var> as follows. First,
remove any text nodes with values of zero length from <var>S6</var>, then
maximally group the results into groups of text nodes and non-text nodes. For each group
of items, if the group is a subsequence of text nodes, copy to
<var>S7</var> a single text node whose value is equal to the concatenated
values of the subsequence; if the group is a subsequence of non-text nodes, copy the
subsequence of items to <var>S7</var>. It is a <termref def="serial-err">serialization error</termref>
<errorref code="0001" class="NR"/> if any item in <var>S7</var> is an
attribute node, a namespace node, or a <termref def="dt-function-item">function</termref>. </p></item><item><p>Create a new sequence <var>S8</var> from <var>S7</var> as follows.
Let <var>S8</var> be a single document node. 
Copy sequence <var>S7</var> to the document node as its children.
</p></item></olist><p><var>S8</var> is the normalized sequence.</p><p>The <termref def="result-tree">result tree</termref> rooted at the document node that is
created by the final step of this sequence
normalization process is the
value to which the rules of the appropriate
output method are applied.  If the sequence
normalization process results
in a <termref def="serial-err">serialization error</termref>, the
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.</p><note><p>If the <code nobreak="false">item-separator</code>
serialization parameter is absent, the sequence normalization process
for a sequence <code nobreak="false">$seq</code> is equivalent
to constructing a document node using the XSLT instruction:</p><!--Text replaced by erratum E6 change 2"--><eg xml:space="preserve">&lt;xsl:document&gt;
  &lt;xsl:copy-of select="$seq" validation="preserve"/&gt;
&lt;/xsl:document&gt;</eg><!--End of text replaced by erratum E6--><p>or the XQuery expression:</p><!--Text replaced by erratum E6 change 3"--><!--End of text replaced by erratum E6--><!-- Start of text removed for defect 20416 --><eg xml:space="preserve">
declare construction preserve;

document { $seq }</eg><!-- End of text removed for defect 20416 --><p>If the <code nobreak="false">item-separator</code>
serialization parameter is present, the sequence normalization process
for a sequence <code nobreak="false">$seq</code> is equivalent to constructing a
document node using the XSLT
instruction:</p><!-- Start of text removed to fix bug 20416 --><!--
<eg xml:space="preserve">
<![CDATA[
<xsl:document>
  <xsl:for-each-group select="$seq"
         group-adjacent=". instance of node()">
    <xsl:sequence select="
            if (current-grouping-key())
            then current-group()
            else string-join(current-group() ! string($i), $sep)"/>
  </xsl:for-each-group>
</xsl:document>
]]></eg>
--><!-- End of text removed to fix bug 20416 --><!-- Start of text added to fix bug 20416 --><eg xml:space="preserve">
&lt;xsl:document&gt;
  &lt;xsl:for-each select="$seq"&gt;
    &lt;xsl:sequence select="if (position() gt 1) 
                          then $sep 
                          else ()"/&gt;

    &lt;xsl:choose&gt;
      &lt;xsl:when test=". instance of node()"&gt;
        &lt;xsl:sequence select="."/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select="."/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:for-each&gt;
&lt;/xsl:document&gt;</eg><!-- End of text added to fix bug 20416 --><p>or the XQuery expression:</p><!-- Start of text removed to fix bug 20416 --><!--
<eg xml:space="preserve">
declare construction preserve;

document {
  for tumbling window $w in $seq
        start when true()
        end $end when $end instance of node()
  return if (count($w) ge 2)
         then string-join($w[count($w)-1], $sep)
         else $w
}</eg>
--><!-- End of text removed to fix bug 20416 --><!-- Start of text added to fix bug 20416 --><eg xml:space="preserve">
declare construction preserve; 

document {
  for $item at $pos in $seq
  let $node := 
    if ($item instance of node()) then 
      $item 
    else 
      text { $item }
  return
    if ($pos eq 1) then
      $node
    else
      ($sep, $node)  
}</eg><!-- End of text added to fix bug 20416 --><p>where the value of the <code nobreak="false">sep</code>
variable is a string whose value is equal to the value of the
<code nobreak="false">item-separator</code> serialization parameter.</p><p>This process results in a <termref def="serial-err">serialization error</termref> <errorref code="0001" class="NR"/>
if 
<!-- Part of text added for defect 20416 -->
<code nobreak="false">$seq</code> contains functions,
attribute nodes or namespace
nodes.</p></note></div1><div1 id="serparam"><head>Serialization Parameters</head><changes><change issue="530" PR="534" date="2023-06-06">
      Added the <code nobreak="false">escape-solidus</code> parameter for JSON serialization.
    </change><change issue="1471" date="2024-10-15">
      Added the <code nobreak="false">json-lines</code> parameter for JSON serialization.
    </change><change issue="938" PR="TODO" date="2025-10-20">
      Added the <code nobreak="false">canonical</code> parameter for XML, XHTML, and JSON serialization.
    </change></changes><p>There are a number of parameters that influence how serialization
is performed. <termref def="host-language">Host languages</termref> <rfc2119>MAY</rfc2119> allow users to specify any or all of these parameters, but
they are not <rfc2119>REQUIRED</rfc2119> to be able to do so. However, the <termref def="host-language">host language</termref>
specification <rfc2119>MUST</rfc2119> specify how the values of all applicable parameters are to be
determined. </p><p>Host languages may also define alternative representations of the values of serialization parameters. For example, both XSLT
  and XQuery allow the boolean values <code nobreak="false">true</code> and <code nobreak="false">false</code> to be written as <code nobreak="false">1</code>/<code nobreak="false">0</code>
  or <code nobreak="false">yes</code>/<code nobreak="false">no</code>. The <code nobreak="false">$options</code> map passed to the <code nobreak="false">fn:serialize</code> function,
  by contrast, requires an <code nobreak="false">xs:boolean</code> value.</p><p>It is a <termref def="serial-err">serialization error</termref> <errorref code="0016" class="PM"/> if a parameter value is invalid for the given parameter.   It
is the responsibility of the <termref def="host-language">host language</termref> to specify how invalid values should be handled at the level of that language.</p><p>The following serialization parameters are defined:</p><table role="medium no-code-break" border="1" summary="Serialization parameters"><col span="1" width="30%"/><col span="1"/><thead><tr><th align="left" rowspan="1" colspan="1">Serialization parameter name</th><th align="left" rowspan="1" colspan="1">Permitted values for parameter</th></tr></thead><tbody><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">allow-duplicate-names</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
This parameter indicates
whether a map item serialized as a JSON object using the JSON output method is 
allowed to contain duplicate member names.  If the value <code nobreak="false">false</code>
is specified, a serialization error <errorref code="0022" class="RE"/> may be raised under certain conditions.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">byte-order-mark</code></td><td rowspan="1" colspan="1">A boolean value, 
  <code nobreak="false">true</code> or <code nobreak="false">false</code>.
          This parameter indicates
          whether the serialized sequence of octets is to be preceded by
          a Byte Order Mark  (See Section 5.1 of
          <bibref ref="UNICODE-ENCODING"/>).  The actual octet order used is
          <termref def="impdep">implementation-dependent</termref>.
          If the encoding defines no Byte Order Mark, or if the Byte Order Mark is
          prohibited for the specific encoding or implementation environment, then
          this parameter is ignored.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">canonical</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">cdata-section-elements</code></td><td rowspan="1" colspan="1">A list of expanded QNames, possibly empty.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">doctype-public</code></td><!--Text replaced by erratum E10 change 1"--><td rowspan="1" colspan="1">A string of
<xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-PubidChar" xlink:type="simple">PubidChar</xnt> characters.
This parameter <rfc2119>MAY</rfc2119> be absent.</td><!--End of text replaced by erratum E10--></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">doctype-system</code></td><!--Text replaced by erratum E10 change 2"--><td rowspan="1" colspan="1">A string of Unicode characters
	that does not include both the characters <char>U+0027</char> and 
	  <char>U+0022</char>.
	This parameter <rfc2119>MAY</rfc2119> be absent.</td><!--End of text replaced by erratum E10--></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">encoding</code></td><td rowspan="1" colspan="1">A string of Unicode characters in the range <char>U+0021</char> 
  through <char>U+007E</char> (that is,
          printable ASCII characters); the value <rfc2119>SHOULD</rfc2119> be a charset
          registered with the Internet Assigned Numbers Authority
          <bibref ref="IANA"/>,  <bibref ref="RFC2978"/> or begin with the
          characters <code nobreak="false">x-</code> or <code nobreak="false">X-</code>.</td></tr><tr diff="add" at="2023-03-31"><td rowspan="1" colspan="1" valign="top"><code nobreak="false">escape-solidus</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
    </td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">escape-uri-attributes</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">html-version</code></td><td rowspan="1" colspan="1">A decimal value.  This parameter <rfc2119>MAY</rfc2119> be absent.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">include-content-type</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">indent</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">item-separator</code></td><td rowspan="1" colspan="1">A string of Unicode characters.  This
parameter <rfc2119>MAY</rfc2119> be absent.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">json-lines</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">json-node-output-method</code></td><td rowspan="1" colspan="1">An expanded QName 
with a 
<termref def="non-null-namespace-URI">non-null
namespace URI</termref>,
or with a <termref def="null-namespace-URI">null 
namespace URI</termref> and a local name equal 
to one of <code nobreak="false">xml</code>, <code nobreak="false">xhtml</code>,
<code nobreak="false">html</code> or 
<code nobreak="false">text</code>. 
If the namespace URI is non-null, 
the parameter
specifies an <termref def="impdef">implementation-defined</termref> 
output method.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">media-type</code></td><td rowspan="1" colspan="1">A string of Unicode characters specifying the media type (MIME
          content type) <bibref ref="RFC2046"/>;
          the charset parameter of
          the media type <rfc2119>MUST NOT</rfc2119> be specified explicitly in the value of
          the <code nobreak="false">media-type</code> parameter.
          If the destination of the serialized output
          is annotated with a media type, this parameter <rfc2119>MAY</rfc2119> be used to
          provide such an annotation.  For example, it <rfc2119>MAY</rfc2119> be used to set
          the media type in an HTTP header.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">method</code></td><td rowspan="1" colspan="1">An expanded QName with a 
<termref def="non-null-namespace-URI">non-null
namespace URI</termref>,
or with a <termref def="null-namespace-URI">null 
namespace URI</termref> and a local name that <rfc2119>MUST</rfc2119> be equal 
to one of <code nobreak="false">xml</code>, <code nobreak="false">xhtml</code>,
<code nobreak="false">html</code>, <code nobreak="false">text</code>, 
<code nobreak="false">json</code>, or <code nobreak="false">adaptive</code>, in which case, the output method specified <rfc2119>MUST</rfc2119> 
be used for serializing. 
If the namespace URI is non-null, 
the parameter
specifies an <termref def="impdef">implementation-defined</termref> 
output method; its behavior is not specified by this document.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">normalization-form</code></td><td rowspan="1" colspan="1">One of the enumerated values <code nobreak="false">NFC</code>, <code nobreak="false">NFD</code>,
          <code nobreak="false">NFKC</code>, <code nobreak="false">NFKD</code>, <code nobreak="false">fully-normalized</code>
          or <code nobreak="false">none</code>, or an
          <termref def="impdef">implementation-defined</termref> value
         of type
         <code nobreak="false">NMTOKEN</code>.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">omit-xml-declaration</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">standalone</code></td><td rowspan="1" colspan="1">Either a boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>, or the value
or <code nobreak="false">omit</code>.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">suppress-indentation</code></td><td rowspan="1" colspan="1">A list of expanded QNames, possibly empty.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">undeclare-prefixes</code></td><td rowspan="1" colspan="1">A boolean value, <code nobreak="false">true</code> or <code nobreak="false">false</code>.
</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">use-character-maps</code></td><td rowspan="1" colspan="1">A list of pairs, possibly empty, with each pair consisting of
          a single Unicode character and a string of Unicode characters.</td></tr><tr><td rowspan="1" colspan="1" valign="top"><code nobreak="false">version</code></td><td rowspan="1" colspan="1">A string of Unicode characters. This
parameter <rfc2119>MAY</rfc2119> be absent.</td></tr></tbody></table><imp-dep-feature>The octet order of the serialized result sequence of 
octets is <termref def="impdep">implementation-dependent</termref>.</imp-dep-feature><imp-def-feature>If the namespace URI is non-null for the <code nobreak="false">method</code> serialization 
parameter, then the parameter specifies an <termref def="impdef">implementation-defined</termref>
output method.</imp-def-feature><p>In those cases where they have no important
effect on the content of the serialized result, details of the
output methods defined by this specification are left unspecified
and are regarded as <termref def="impdep">implementation-dependent</termref>.
Whether a <termref def="serializer">serializer</termref> uses
apostrophes or quotation marks to delimit attribute values in the
XML output method is an example of such a detail.</p><imp-dep-feature>In those cases where they have no important
effect on the content of the serialized result, details of the
output methods defined by this specification are left unspecified
and are regarded as <termref def="impdep">implementation-dependent</termref>.</imp-dep-feature><p>The detailed semantics of each parameter will be described
separately for each output method for which it is applicable. If the
semantics of a parameter are not described for an output method, then
it is not applicable to that output method.</p><p>Implementations <rfc2119>MAY</rfc2119> define additional serialization 
parameters, and <rfc2119>MAY</rfc2119>
allow users to do so. For this purpose, the name of a serialization
parameter is considered to be a QName; the parameters listed above are
QNames whose
<termref def="dt-expanded-qname">expanded-QName</termref>
has a <termref def="null-namespace-URI">null namespace URI</termref>,
while any additional serialization parameters
that are either
<termref def="impdef">implementation-defined</termref> or
defined by the <termref def="host-language">host language</termref>
<rfc2119>MUST</rfc2119> have names that are namespace-qualified.
Any such
additional serialization parameters <rfc2119>MUST NOT</rfc2119> be in the namespace
<code nobreak="false">https://www.w3.org/2010/xslt-xquery-serialization</code>.
A <termref def="host-language">host language</termref> <rfc2119>MAY</rfc2119>
specify the means by which an implementation can define such an additional
serialization parameter, and implementations <rfc2119>MAY</rfc2119> provide
mechanisms by which users can define such an additional serialization
parameter.
If the serialization method is one of the six
methods <code nobreak="false">xml</code>, <code nobreak="false">html</code>, 
<code nobreak="false">xhtml</code>, <code nobreak="false">text</code>, 
<code nobreak="false">json</code>, or <code nobreak="false">adaptive</code>
 then the additional serialization parameters <rfc2119>MAY</rfc2119>
affect the output of the <termref def="serializer">serializer</termref> to the extent (but only to the extent)
that this specification leaves the output <termref def="impdef">implementation-defined</termref> or
<termref def="impdep">implementation-dependent</termref>. For example, such parameters might control whether
namespace declarations on an element are written before or after the
attributes of the element, or they might define the number of space or tab
characters to be inserted when the <code nobreak="false">indent</code> parameter is set to 
<code nobreak="false">true</code>; but they
could not instruct the <termref def="serializer">serializer</termref>
to suppress the error that occurs when the
HTML output method encounters
characters
that are not permitted
(see error <errorref code="0014" class="RE"/>).</p><imp-def-feature>The effect of additional serialization parameters on the output of the <termref def="serializer">serializer</termref>, 
where the name of such a parameter <rfc2119>MUST</rfc2119> be namespace-qualified, is 
<termref def="impdef">implementation-defined</termref> 
or <termref def="impdep">implementation-dependent</termref>.  
The extent of this effect on the output <rfc2119>MUST NOT</rfc2119> 
override the provisions of this specification. 
</imp-def-feature><div2 id="serparams-in-xdm-instance"><head>Setting Serialization Parameters by Means of a Parameter Document</head><p>A <termref def="host-language">host language</termref> <rfc2119>MAY</rfc2119> provide, by reference to this
section, a mechanism by 
which the settings of serialization parameters are supplied in the form of 
an <phrase diff="chg" at="2023-11-01"><code nobreak="false">output:serialization-parameters</code> element node.</phrase></p><p diff="add" at="2023-11-01"><termdef id="dt-parameter-document" term="parameter document">An 
    <code nobreak="false">output:serialization-parameters</code> element node
  used to hold the settings of serialization parameters is referred to as a <term>parameter document</term></termdef>.</p><note><p>The use of the word <term>document</term> does not imply that the 
  <code nobreak="false">output:serialization-parameters</code> element must be the outermost element of an XDM document,
although this will often be the case.</p></note><p>The <phrase diff="chg" at="2023-11-01"><termref def="dt-parameter-document"/></phrase> 
    <rfc2119>MUST</rfc2119> be processed as if by the
procedure described below.</p><p>With the exception of the <code nobreak="false">use-character-maps</code> parameter,
the setting of each serialization parameter
defined in this specification
is equal to the result of
evaluating the XQuery expression</p><eg xml:space="preserve">
document { . } 
   /output:serialization-parameters
   /(validate lax { 
      output:*[local-name() eq $param-name] 
   })
   /data(@value)
</eg><p>
or equivalently the XSLT instructions
</p><eg xml:space="preserve">
&lt;xsl:sequence&gt;
  &lt;xsl:variable name="validated-instance"&gt;
    &lt;xsl:document validation="lax"&gt;
      &lt;xsl:sequence select="
        self::output:serialization-parameters
        /output:*
       [local-name() eq $param-name]"/&gt;
    &lt;/xsl:document&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:sequence select="$validated-instance
                        /data(@value)"/&gt;
&lt;/xsl:sequence&gt;
</eg><p>with the <phrase diff="chg" at="2023-11-01"><termref def="dt-parameter-document"/></phrase> as the
  <phrase diff="chg" at="2023-10-30">context value</phrase>, the
<code nobreak="false">param-name</code> variable 
<phrase>bound to</phrase> 
a value of type
<code nobreak="false">xs:string</code> equal to 
the local part of the name of the particular serialization parameter, and 
the other components of the dynamic context and static context as 
specified in the subsequent tables.  If in any case evaluating this 
expression would yield an error,
<termref def="serial-err">serialization error</termref>
<errorref code="0017" class="PM"/>
results.</p><p>If the result of evaluating this expression for a particular serialization 
parameter is the empty sequence, then</p><olist><item><p>If the parameter is either <code nobreak="false">cdata-section-elements</code> or 
<code nobreak="false">suppress-indentation</code>, and the result of evaluating
the XQuery expression</p><eg xml:space="preserve">
document { . }
/output:serialization-parameters
/(validate lax {  
   output:*[local-name() eq $param-name]
})
</eg><p>
or equivalently the XSLT instructions
</p><eg xml:space="preserve">
&lt;xsl:sequence&gt;
  &lt;xsl:variable name="validated-instance"&gt;
    &lt;xsl:document select="." validation="lax"&gt;
      &lt;xsl:sequence select="
        self::output:serialization-parameters
        /output:*
       [local-name() eq $param-name]"/&gt;
    &lt;/xsl:document&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:sequence select="$validated-instance"/&gt;
&lt;/xsl:sequence&gt;
</eg><p>with the same settings of the static context and dynamic context is not an 
empty sequence, the setting of the parameter is the empty list;</p></item><item><p>otherwise, the setting of the parameter is
absent.</p></item></olist><p>The components of the static context used in evaluating the XQuery 
expressions or XSLT instructions
are as defined in the following table.</p><table role="medium no-code-break" border="1" summary="Settings of static context components used in extracting serialization parameter settings from a parameter document"><thead><tr><th rowspan="1" colspan="1">Static Context Component</th><th rowspan="1" colspan="1">XQuery or XSLT</th><th rowspan="1" colspan="1">Setting</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">XPath 1.0 compatibility mode</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">false</td></tr><tr><td rowspan="2" colspan="1">Statically known namespaces</td><td rowspan="1" colspan="1">XQuery</td><td rowspan="1" colspan="1">The pair
(output,http://www.w3.org/2010/xslt-xquery-serialization)
</td></tr><tr><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">The pairs
(output,http://www.w3.org/2010/xslt-xquery-serialization),
(xsl,http://www.w3.org/1999/XSL/Transform)
</td></tr><tr><td rowspan="1" colspan="1">Default element/type namespace</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">"none"</td></tr><tr><td rowspan="1" colspan="1">Default function namespace</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">http://www.w3.org/2005/xpath-functions</td></tr><tr><td rowspan="1" colspan="1">In-scope schema types, In-scope element declarations,
Substitution groups, In-scope attribute declarations</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">As defined by the schema for serialization parameters
(<specref ref="serparams-schema"/>)
and any additional <termref def="impdef">implementation-defined</termref>
in-scope schema components
</td></tr><tr><td rowspan="1" colspan="1">In-scope variables</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">{param-name}</td></tr><tr><td rowspan="1" colspan="1"><phrase diff="chg" at="2023-10-30">Context value</phrase> static type</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1"><code nobreak="false">node()</code></td></tr><tr><td rowspan="1" colspan="1">Statically known
function signatures</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">{<code nobreak="false">fn:data($arg as item()*) as xs:anyAtomicType*</code>},
{<code nobreak="false">fn:local-name($arg as node()?) as xs:string</code>}</td></tr><tr><td rowspan="1" colspan="1">Statically known collations</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1"> { (http://www.w3.org/2005/xpath-functions/collation/codepoint,
The Unicode codepoint collation ) }
</td></tr><tr><td rowspan="1" colspan="1">Default collation</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">The Unicode codepoint collation</td></tr><tr><td rowspan="1" colspan="1">Construction mode</td><td rowspan="1" colspan="1">XQuery</td><td rowspan="1" colspan="1">strip</td></tr><tr><td rowspan="1" colspan="1">Ordering mode</td><td rowspan="1" colspan="1">XQuery</td><td rowspan="1" colspan="1">ordered</td></tr><tr><td rowspan="1" colspan="1">Default order for empty sequences</td><td rowspan="1" colspan="1">XQuery</td><td rowspan="1" colspan="1">least</td></tr><tr><td rowspan="1" colspan="1">Boundary space policy</td><td rowspan="1" colspan="1">XQuery</td><td rowspan="1" colspan="1">strip</td></tr><tr><td rowspan="1" colspan="1">Copy-namespaces mode</td><td rowspan="1" colspan="1">XQuery</td><td rowspan="1" colspan="1">(preserve,inherit)</td></tr><tr><td rowspan="1" colspan="1">Base URI</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">Absent</td></tr><tr><td rowspan="1" colspan="1">Statically known documents</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Statically known collections</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Statically known default collection type</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1"><code nobreak="false">node()*</code></td></tr><tr><td rowspan="1" colspan="1">Statically known decimal formats</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Set of named keys</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">{}</td></tr><tr><td rowspan="1" colspan="1">Values of system
properties</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Set of available
instructions</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">The set of all instructions defined
by <bibref ref="xslt-40"/></td></tr></tbody></table><imp-def-feature>
<termref def="impdef">Implementation-defined</termref> schema components
<rfc2119>MAY</rfc2119> be included in the set of schema components
that are used in evaluating an XQuery expression or XSLT instruction
in the process of using a <termref def="dt-parameter-document"/> to determine the 
serialization parameters.</imp-def-feature><p>The remaining components of the dynamic context used in evaluating the 
XQuery expressions
or XSLT instructions
in the preceding table are as defined in the following 
table.</p><table role="medium no-code-break" border="1" summary="Settings of dynamic context components used in extracting serialization parameter settings from a parameter document"><thead><tr><th rowspan="1" colspan="1">Dynamic Context Component</th><th rowspan="1" colspan="1">XQuery or XSLT</th><th rowspan="1" colspan="1">Setting</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">Context position</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">1</td></tr><tr><td rowspan="1" colspan="1">Context size</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">1</td></tr><tr><td rowspan="1" colspan="1">Variable values</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">The <code nobreak="false">param-name</code> variable has
a value of type <code nobreak="false">xs:string</code> equal to the local part of the name
of the serialization parameter under consideration</td></tr><tr><td rowspan="1" colspan="1">Function implementations</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">The implementation of <code nobreak="false">fn:data</code></td></tr><tr><td rowspan="1" colspan="1">Current dateTime</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">Absent</td></tr><tr><td rowspan="1" colspan="1">Implicit timezone</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">Absent</td></tr><tr><td rowspan="1" colspan="1">Available documents</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Available collections</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Default collection</td><td rowspan="1" colspan="1">Both</td><td rowspan="1" colspan="1">None</td></tr><tr><td rowspan="1" colspan="1">Current template rule</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">Absent</td></tr><tr><td rowspan="1" colspan="1">Current mode</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">The default mode</td></tr><tr><td rowspan="1" colspan="1">Current group</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">Absent</td></tr><tr><td rowspan="1" colspan="1">Current grouping key</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">Absent</td></tr><tr><td rowspan="1" colspan="1">Current captured substrings</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">The empty sequence</td></tr><tr><td rowspan="1" colspan="1">Output state</td><td rowspan="1" colspan="1">XSLT</td><td rowspan="1" colspan="1">Temporary output state</td></tr></tbody></table><p>In the case of the <code nobreak="false">use-character-maps</code> parameter, the
XQuery
expression</p><eg xml:space="preserve">
document { . }
/output:serialization-parameters
/ ( validate lax { output:use-character-maps } )
/output:character-map[@character eq $char]
/string(@map-string)
</eg><p>
or equivalently the XSLT instructions
</p><eg xml:space="preserve">
&lt;xsl:sequence&gt;
  &lt;xsl:variable name="validated-instance"&gt;
    &lt;xsl:document validation="lax"&gt;
      &lt;xsl:sequence select="
        self::output:serialization-parameters
         /output:use-character-maps"/&gt;
    &lt;/xsl:document&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:sequence select="$validated-instance                          
                        /output:character-map
                        [@character eq $char]
                        /string(@map-string)"/&gt;
&lt;/xsl:sequence&gt;
</eg><p>is evaluated for each Unicode character that is permitted in an XML 
document.  The dynamic context and static context used to evaluate the 
expression are as defined above, except that the component <code nobreak="false">In-scope variables</code> is the set 
{<code nobreak="false">char</code>} and the value of the variable "<code nobreak="false">char</code>"
is a value of type <code nobreak="false">xs:string</code>
of length one whose value is the Unicode character under consideration. If 
the result of evaluating the expression is not an empty sequence, the pair 
consisting of the Unicode character and the result of evaluating the 
expression is part of the list of pairs in the value of the 
<code nobreak="false">use-character-maps</code> parameter.  It is a
<termref def="serial-err">serialization error</termref>
<errorref code="0018" class="PM"/>
if the result of evaluating this expression for any character is a 
sequence of length greater than one.</p><p>Using the same settings of the components of the dynamic context and 
static context,
<termref def="serial-err">serialization error</termref>
<errorref code="0019" class="PM"/>
results if the result 
of evaluating the following
XQuery expression is not true
</p><eg xml:space="preserve">
(document { . })/output:serialization-parameters
   /(count(distinct-values(*/node-name(.))) eq (count(*)))
</eg><p>
or equivalently if the result of evaluating the following XSLT
instructions is not true.
</p><eg xml:space="preserve">
&lt;xsl:sequence&gt;
  &lt;xsl:variable name="doc"&gt;
    &lt;xsl:document&gt;
      &lt;xsl:sequence select="."/&gt;
    &lt;/xsl:document&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:sequence
    select="$doc/output:serialization-parameters
                /(count(distinct-values(
                    */node-name(.))) 
                eq (count(*)))"/&gt;
&lt;/xsl:sequence&gt;
</eg><p>The result of evaluating either
  will be false if the <phrase diff="chg" at="2023-11-01"><termref def="dt-parameter-document"/></phrase> 
supplies a value
for any particular serialization parameter
more than once, or will be the
empty sequence if the <phrase diff="chg" at="2023-11-01"><termref def="dt-parameter-document"/></phrase> 
 <phrase diff="chg" at="2023-11-01">
is not an element node whose local name is
<code nobreak="false">serialization-parameters</code> and whose namespace URI is
   <!-- TODO: by what mechanism do we update http://www.w3.org/2010/xslt-xquery-serialization ? -->
<code nobreak="false">http://www.w3.org/2010/xslt-xquery-serialization</code>.</phrase></p><note><p>A <termref def="serializer">serializer</termref> or implementation of a 
  <termref def="host-language">host language</termref> does not need to 
be accompanied by an XQuery processor nor by a general-purpose schema 
validator in order to meet the requirements of this section.  It merely 
needs to be capable of extracting values from an XDM instance that 
conforms to the schema for serialization parameters, while checking that 
the constraints implied by the schema and additional constraints implied 
by the XQuery validate expression or explicitly stated in this section are 
satisfied.</p></note><p>The <termref def="host-language">host language</termref> <rfc2119>MAY</rfc2119> provide additional mechanisms for overriding the 
values of any serialization parameters specified through the mechanism 
defined in this section, as well as additional mechanisms for specifying 
the values of any serialization parameters whose values
are absent
after applying the mechanism defined in this section.</p><p>If the <phrase diff="chg" at="2023-11-01"><termref def="dt-parameter-document"/></phrase> 
    contains elements or attributes
that are in a namespace other than 
<code nobreak="false">http://www.w3.org/2010/xslt-xquery-serialization</code>, the
implementation <rfc2119>MAY</rfc2119> interpret them to specify the
values of <termref def="impdef">implementation-defined</termref> 
serialization parameters in an
<termref def="impdef">implementation-defined</termref> manner.</p><imp-def-feature>If a <phrase diff="chg" at="2023-11-01"><termref def="dt-parameter-document"/></phrase> 
contains elements or attributes that are in a namespace other than
<code nobreak="false">http://www.w3.org/2010/xslt-xquery-serialization</code>, the
implementation <rfc2119>MAY</rfc2119> interpret them to specify the
values of <termref def="impdef">implementation-defined</termref>
serialization parameters in an
<termref def="impdef">implementation-defined</termref> manner.
</imp-def-feature><example><p>The following XML document, if 
    <phrase diff="chg" at="2023-11-01">parsed as a <termref def="dt-parameter-document"/></phrase> 
and processed using the mechanism described in this section,
would specify the settings of the <code nobreak="false">method</code>, <code nobreak="false">version</code>
and <code nobreak="false">indent</code> serialization parameters with the values
<code nobreak="false">xml</code>, <code nobreak="false">1.0</code> and <code nobreak="false">true</code>, respectively.
</p><eg xml:space="preserve">
&lt;output:serialization-parameters 
    xmlns:output 
    = "http://www.w3.org/2010/xslt-xquery-serialization"&gt;
  &lt;output:method value="xml"/&gt;
  &lt;output:version value="1.0"/&gt;
  &lt;output:indent value="yes"/&gt;
&lt;/output:serialization-parameters&gt;
</eg><p>The following document would specify the value of the
<code nobreak="false">cdata-section-elements</code> serialization parameter with value equal to the
pair of expanded QNames
(<code nobreak="false">http://example.org/book/chapter</code>,<code nobreak="false">heading</code>) and
(<code nobreak="false">http://example.org/book</code>,<code nobreak="false">footnote</code>)</p><eg xml:space="preserve">
&lt;output:serialization-parameters
    xmlns:output
    = "http://www.w3.org/2010/xslt-xquery-serialization"
    xmlns:book="http://example.org/book"
    xmlns="http://example.org/book/chapter"&gt;
  &lt;output:cdata-section-elements value="heading book:footnote"/&gt;
&lt;/output:serialization-parameters&gt;
</eg><p>The following document would specify the value of the <code nobreak="false">method</code>
serialization parameter with the value <code nobreak="false">html</code>.</p><p>Notice that in this example, the default namespace declaration
in scope has no effect on the interpretation of the setting of the
<code nobreak="false">method</code> parameter.</p><eg xml:space="preserve">
&lt;output:serialization-parameters
    xmlns:output
    = "http://www.w3.org/2010/xslt-xquery-serialization"
    xmlns="http://example.org/ext"&gt;
  &lt;output:method value="html"/&gt;
&lt;/output:serialization-parameters&gt;
</eg><p>The following document would specify the value of the <code nobreak="false">method</code>
serialization parameter with value equal to the expanded QName
(<code nobreak="false">http://example.org/ext</code>, <code nobreak="false">jsp</code>), and the
<code nobreak="false">use-character-maps</code> parameter with value equal to the list of
pairs, <code nobreak="false">(«, &lt;%), (», %&gt;)</code>.</p><eg xml:space="preserve">
&lt;output:serialization-parameters
    xmlns:output
    = "http://www.w3.org/2010/xslt-xquery-serialization"
    xmlns:ext="http://example.org/ext"&gt;
  &lt;output:method value="ext:jsp"/&gt;
  &lt;output:use-character-maps&gt;
    &lt;output:character-map character="&amp;#xAB;" map-string="&amp;lt;%"/&gt;
    &lt;output:character-map character="&amp;#xBB;" map-string="%&amp;gt;"/&gt;
  &lt;/output:use-character-maps&gt;
&lt;/output:serialization-parameters&gt;
</eg></example></div2></div1><div1 id="serphases"><head>Phases of Serialization</head><!--Text replaced by erratum E2 change 1"--><p>For the XML, HTML, XHTML and Text output methods, 
serialization
comprises six phases of processing 
(preceded by the sequence normalization process 
described in <specref ref="serdm"/>).<!--End of text replaced by erratum E2-->
<!--Should the below be implementation-dependent?  -sb 3/16/05-->

For the JSON and Adaptive
output methods, serialization is described in <specref ref="json-output"/> and 
  <specref ref="adaptive-output"/> respectively.


</p><p>For an <termref def="impdef">implementation-defined</termref>
output method, any of these phases <rfc2119>MAY</rfc2119> be skipped
or <rfc2119>MAY</rfc2119> be performed in a different order than is
specified here.  For the output methods defined in this specification,
these phases are carried out sequentially as follows:</p><olist><item><p>A <code nobreak="false">meta</code> element is added to the sequence, 
<phrase diff="chg" at="2023-02-09">possibly replacing existing <code nobreak="false">meta</code> elements</phrase>, as 
controlled by the <code nobreak="false">include-content-type</code> parameter 
for the XHTML and HTML output methods. This step is skipped for the 
other output methods defined by this 
specification.
</p></item><item><p><emph>Markup generation</emph> produces the character representation of
those parts of the serialized result that describe the structure of the 
sequence.  In the cases of the XML, HTML and XHTML
output methods, this phase produces the character representations 
of the following:</p><ulist><item><p>the document type declaration;
</p></item><item><p>start tags and end tags (except for
attribute values, whose representation is produced by the character
expansion phase);
</p></item><item><p>processing instructions; and</p></item><item><p>comments.</p></item></ulist><!--Text replaced by erratum E8 change 1"--><p>In the cases of the XML and XHTML output methods,
this phase also produces the following:</p><ulist><item><p>the XML or text declaration; and</p></item><item><p>empty element tags (except for the attribute
values);</p></item></ulist><p>
In the case of the text output method,
this phase replaces the single
document node produced by <termref def="sequence-normalization">sequence
normalization</termref> with a new document node that has exactly one child,
which is a text node.  The string value of the new text node is the string value
of the document node that was produced by sequence normalization.
</p><!--End of text replaced by erratum E8--></item><item><p><emph>Character expansion</emph> 
is concerned with the representation of characters appearing in text 
and attribute nodes in the sequence. 
For each text and attribute node, 
the following rules are applied in sequence. 
</p><olist><item><p>
If the node is an attribute that is 
a <termref def="uri-attribute-values">URI attribute value</termref> 
and the <code nobreak="false">escape-uri-attributes</code> parameter is set to 
require escaping of URI attributes, 
apply <termref def="uri-escaping">URI escaping</termref> as defined below, 
and skip rules b-e. Otherwise, continue with rule b.</p><p><termdef term="URI Escaping" id="uri-escaping"><term>URI escaping</term> consists of the following three steps applied in sequence to the content of 
<termref def="uri-attribute-values">URI attribute values</termref>:</termdef>
</p><olist><item><p>normalize to NFC using the method defined in <xspecref spec="FO40" ref="func-normalize-unicode"/></p></item><item><p>percent-encode any special characters in the URI using the method defined in <xspecref spec="FO40" ref="func-escape-html-uri"/></p></item><item><p>escape according to
<!-- Start of text changed for Bug 8206 (Erratum SE.E18) -->
the rules of the XML or HTML output
method, whichever is applicable, any characters that require
<!-- End of text changed for Bug 8206 (Erratum SE.E18) -->
escaping, and any characters that cannot be represented in the
selected encoding. 
For example, replace <code nobreak="false">&lt;</code> with <code nobreak="false">&amp;lt;</code>
(See also section <specref ref="HTML_CHARDATA"/>).
</p></item></olist><p>
<termdef term="URI attribute values" id="uri-attribute-values"> The values of attributes listed in 
<specref ref="list-of-uri-attributes"/> are <term>URI attribute values</term>. 
Attributes are not considered to be URI attributes simply because they are namespace declaration attributes or have the type annotation <code nobreak="false">xs:anyURI</code>.</termdef></p></item><item><p>
If the node is a text node whose parent element is selected by the rules of the 
<code nobreak="false">cdata-section-elements</code> parameter for the applicable output method, 
create CDATA sections as described below, and skip rules c-e. Otherwise, continue with rule c.
</p><p>Apply the following two processes in sequence to create CDATA sections</p><olist><item><p><termref def="unicode-normalization">Unicode Normalization</termref> if requested by the <code nobreak="false">normalization-form</code> parameter.</p></item><item><p>The application of changes as detailed in the description of the <code nobreak="false">cdata-section-elements</code> parameter for the applicable output method.</p></item></olist></item><item><p>Apply character mapping as determined by the 
<code nobreak="false">use-character-maps</code> parameter for the applicable output method.  
For characters that were substituted by this process, skip rules d and e. 
For the remaining characters that were not modified by character mapping, continue with rule d. 
</p></item><item><p>Apply <termref def="unicode-normalization">Unicode Normalization</termref> if requested by the <code nobreak="false">normalization-form</code> parameter.  </p><p>
<termdef term="Unicode Normalization" id="unicode-normalization"><term>Unicode Normalization</term>
is the process of removing alternative representations of equivalent sequences from textual data,
to convert the data into a form that can be binary-compared for equivalence, as specified in 
<bibref ref="UNICODE-NORMALIZATION-FORM"/>.   
For specific recommendations for character normalization on the World Wide Web, 
see <bibref ref="charmod-norm"/>.</termdef></p><p>
The meanings associated with the possible values of the <code nobreak="false">normalization-form</code> parameter 
are defined in section <specref ref="XML_NORMALIZATION-FORM"/>. </p><p>Continue with step e.
</p></item><!-- Start of text changed for Bug 8206 (Erratum SE.E18) --><item><p>Escape according to
the rules of the XML or HTML output
method, whichever is applicable,
<!-- End of text changed for Bug 8206 (Erratum SE.E18) -->
any characters (such as <code nobreak="false">&lt;</code> and <code nobreak="false">&amp;</code>) where XML or HTML requires 
escaping, 
and any characters that cannot be represented in the selected encoding. 
For example, replace <code nobreak="false">&lt;</code> with <code nobreak="false">&amp;lt;</code>. 
(See also section <specref ref="HTML_CHARDATA"/>).
For characters such as <code nobreak="false">&gt;</code> where XML defines a built-in entity but does not 
require its use in all circumstances, it is implementation-dependent whether the character 
is escaped.
</p></item></olist></item><item><p><emph>Indentation</emph>, as controlled by
the <code nobreak="false">indent</code> parameter and the
<code nobreak="false">suppress-indentation</code> parameter, <rfc2119>MAY</rfc2119>
add or remove
whitespace according to the rules defined by the applicable output method.</p></item><item><p><emph>Encoding</emph>, as controlled by the
<code nobreak="false">encoding</code> parameter, converts the character sequence
produced by the previous phases into an octet stream.</p><note><p>Serialization is defined only in terms of encoding the result as a stream of octets.  
However, a <termref def="serializer">serializer</termref> <rfc2119>MAY</rfc2119> 
provide an option that allows the encoding phase to be skipped, so
that the result of serialization can be encoded in a way required by a particular destination (e.g., a Java StringBuffer).
The effect of any such option is <termref def="impdef">implementation-defined</termref>, 
and a <termref def="serializer">serializer</termref> is not required to support such an option.
</p><imp-def-feature>The effect of providing an option that allows the encoding phase to be skipped, 
so that the result of serialization can be encoded in a way required by a particular destination (e.g., a Java StringBuffer), 
is <termref def="impdef">implementation-defined</termref>.  
The <termref def="serializer">serializer</termref> is not required  to support such an option.
<!--It's not clear to me that this should be a formal implementation-defined item, 
since it's in a note, but it's here for review.  -sb 3/16/05--></imp-def-feature></note></item><item><p><emph>Canonicalization</emph>, as controlled by
the <code nobreak="false">canonical</code> parameter, <rfc2119>MAY</rfc2119>
revert any previous changes, or make new changes, according to the rules defined by the applicable output method.</p></item></olist></div1><div1 id="xml-output"><head>XML Output Method</head><p>The XML output method serializes the normalized sequence as an XML entity that
<rfc2119>MUST</rfc2119> satisfy the rules for either a well-formed XML document entity, a well-formed XML
external general parsed entity, or both.
A <termref def="serial-err">serialization error</termref> <errorref code="0003" class="RE"/> results if the
<termref def="serializer">serializer</termref>
is unable to satisfy those rules,
except for content modified by the character expansion phase of serialization,
as described in <specref ref="serphases"/>.
The effects of the character expansion phase could result in the serialized output 
being not well-formed, but will not result in a <termref def="serial-err">serialization error</termref>.  
If a <termref def="serial-err">serialization error</termref> results, the 
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.</p><p>If the document node of the
normalized sequence has a single element
node child and no text node children,
then the serialized output
is a well-formed XML document entity, and the serialized output
<rfc2119>MUST</rfc2119> conform to the
appropriate version of the
XML Namespaces Recommendation <bibref ref="xml-names"/>
or <bibref ref="xml-names11"/>.
If the normalized sequence does not take this form, then
the serialized output is a well-formed XML external general parsed entity,
which, when referenced within a trivial XML document wrapper
like this:</p><eg xml:space="preserve">
&lt;?xml version="<emph>version</emph>"?&gt;
&lt;!DOCTYPE doc [
&lt;!ENTITY e SYSTEM "<emph>entity-URI</emph>"&gt;
]&gt;
&lt;doc&gt;&amp;e;&lt;/doc&gt;</eg><p>where <code nobreak="false">entity-URI</code> is a URI for the entity,
and the value of the <code nobreak="false">version</code>
pseudo-attribute is the value of the <code nobreak="false">version</code>
parameter, produces a
document which <rfc2119>MUST</rfc2119> itself be a
well-formed XML document conforming
to the
corresponding version of the
XML Namespaces Recommendation <bibref ref="xml-names"/>
or <bibref ref="xml-names11"/>.</p><p><termdef id="reconstructed-tree" term="reconstructed tree">A <term>reconstructed tree</term> may be
constructed by parsing the XML document and converting it into an
document node as specified in 
<bibref ref="xpath-datamodel-40"/>.</termdef>
The result of serialization <rfc2119>MUST</rfc2119> be such that the <termref def="reconstructed-tree">reconstructed tree</termref>
is the same as the <termref def="result-tree">result tree</termref> except for the following permitted differences:</p><ulist><item><p>If the document was produced by adding a document wrapper, as
described above, then it will contain an extra <code nobreak="false">doc</code>
element as the document element.</p></item><item><p>The order of attribute and namespace nodes in the two trees <rfc2119>MAY</rfc2119> be
different.</p></item><item><p>
The following properties of corresponding nodes
in the two trees <rfc2119>MAY</rfc2119> be different:</p><ulist><item><p>the base-uri property of document nodes and element nodes;</p></item><item><p>the document-uri and unparsed-entities properties of document
nodes;</p></item><item><p>the type-name and typed-value properties of element and attribute
nodes;</p></item><item><p>the nilled property of element nodes;</p></item><item><p>the content property of text nodes, due to the effect of the
<code nobreak="false">indent</code> and <code nobreak="false">use-character-maps</code>
parameters.</p></item></ulist></item><item><p>The <termref def="reconstructed-tree">reconstructed tree</termref> <rfc2119>MAY</rfc2119> contain additional attributes and text nodes resulting from the
expansion of default and fixed values in its DTD or schema;
also, in the presence of a DTD, non-CDATA attributes may lose whitespace
characters as a result of attribute value normalization.</p></item><item><p>The type annotations of the nodes in the two trees <rfc2119>MAY</rfc2119> be different. 
Type annotations in a <termref def="result-tree">result tree</termref> are discarded when the tree is serialized. 
Any new type annotations obtained by parsing the document will depend on whether the serialized XML document is assessed against a schema, 
and this <rfc2119>MAY</rfc2119> result in type annotations that are different from
those in the original <termref def="result-tree">result tree</termref>.
</p><note><p>In order to influence the type annotations in the
tree that would result from processing a serialized XML document,
the author of the XSLT stylesheet, XQuery expression or other process
might wish to create the <termref def="dt-input-tree"/> so that it makes use of mechanisms provided by
<bibref ref="xmlschema-1"/>, such as <code nobreak="false">xsi:type</code> and
<code nobreak="false">xsi:schemaLocation</code> attributes.  The serialization process
will not automatically create such attributes in the serialized
document if those attributes were not part of the <termref def="result-tree">result tree</termref> that is
to be serialized.</p><p>Similarly, it is possible that an element node in
  the <termref def="dt-input-tree"/> has the <code nobreak="false">nilled</code>
property with the value <code nobreak="false">true</code>, but no <code nobreak="false">xsi:nil</code>
attribute.  The serialization process will not create such an attribute
in the serialized document simply to reflect the value of the property.
The value of the <code nobreak="false">nilled</code> property has no direct effect on
the serialized result.
</p></note></item><item><p>Additional namespace nodes <rfc2119>MAY</rfc2119> be present
in the <termref def="reconstructed-tree">reconstructed tree</termref> if the serialization process
did not undeclare one or more namespaces,
as described in <specref ref="xml-undeclare-NS"/>,
  and the <termref def="dt-input-tree"/> contained an element node
with a namespace node that declared some prefix, but a child element
of that node did not have any namespace node that declared the same prefix.</p><p>
The <termref def="result-tree">result tree</termref> <rfc2119>MAY</rfc2119> contain namespace nodes
that are not present in the <termref def="reconstructed-tree">reconstructed tree</termref>, as the process of creating an instance
of the data model <rfc2119>MAY</rfc2119> ignore namespace declarations in some circumstances.
See <xspecref spec="DM40" ref="const-infoset-element"/> and
<xspecref spec="DM40" ref="const-psvi-element"/> of <bibref ref="xpath-datamodel-40"/>
for additional information.
</p></item><item><p>If the <code nobreak="false">indent</code> parameter has
the value <code nobreak="false">true</code>,
</p><ulist><item><p>additional text nodes consisting of
whitespace characters <rfc2119>MAY</rfc2119> be present in the <termref def="reconstructed-tree">reconstructed tree</termref>; and</p></item><item><p>text nodes in the <termref def="result-tree">result tree</termref> that contained only whitespace
characters <rfc2119>MAY</rfc2119> correspond to text nodes in the <termref def="reconstructed-tree">reconstructed tree</termref> that contain additional
whitespace characters that were not present in the <termref def="result-tree">result tree</termref></p></item></ulist><p>See <specref ref="xml-indent"/> for more information on the
<code nobreak="false">indent</code> parameter.</p></item><item><p>Additional nodes <rfc2119>MAY</rfc2119> be present in the
<termref def="reconstructed-tree">reconstructed tree</termref> due to the effect of character mapping in the character expansion phase,
and the values of attribute nodes and text nodes in the
<termref def="reconstructed-tree">reconstructed tree</termref> <rfc2119>MAY</rfc2119> be different from those in the <termref def="result-tree">result tree</termref>, due to
the effects of URI expansion, character mapping
and <termref def="unicode-normalization">Unicode Normalization</termref> in
the character expansion phase of serialization.
</p><note><p>The <code nobreak="false">use-character-maps</code> parameter can
cause arbitrary characters to be inserted into the serialized XML document
in an unescaped form, including characters that would be considered to be
part of XML markup.  Such characters could result in arbitrary new element
nodes, attribute nodes, and so on, in the <termref def="reconstructed-tree">reconstructed tree</termref> that results from
processing the serialized XML document.</p></note></item></ulist><p>A consequence of this rule is that certain characters
<rfc2119>MUST</rfc2119> be output as character
references, to ensure that they survive
the round trip through serialization and parsing.
Specifically:</p><ulist><item><p>In text nodes, the characters <char>U+000D</char>, <char>U+0085</char>, and <char>U+2028</char>
      <rfc2119>MUST</rfc2119> be output respectively as
      "<code nobreak="false">&amp;#xD;</code>", "<code nobreak="false">&amp;#x85;</code>", and
      "<code nobreak="false">&amp;#x2028;</code>", or their equivalents</p></item><item><p>In attribute nodes, the characters 
      <char>U+000D</char>, <char>U+000A</char>, <char>U+0009</char>, 
      <char>U+0085</char>, and <char>U+2028</char>
      <rfc2119>MUST</rfc2119> be output respectively
      as "<code nobreak="false">&amp;#xD;</code>", "<code nobreak="false">&amp;#xA;</code>", "<code nobreak="false">&amp;#x9;</code>",
      "<code nobreak="false">&amp;#x85;</code>", and "<code nobreak="false">&amp;#x2028;</code>", or their equivalents.</p></item><item><p>In both text nodes and attribute nodes, control characters
      <char>U+0001</char> through <char>U+001F</char> and <char>U+007F</char> through 
      <char>U+009F</char> (except <char>U+0009</char>, 
      <char>U+000A</char>, and <char>U+000D</char>, and <char>U+0085</char>) <rfc2119>MUST</rfc2119> be
      output as character references.</p></item></ulist><p>For example, an attribute with the value "x" followed by "y"
separated by a newline will result in the output
<code nobreak="false">"x&amp;#xA;y"</code> (or with any equivalent character
reference). The XML output cannot be "x" followed by a literal newline
followed by a "y" because after parsing, the attribute value would be
<code nobreak="false">"x y"</code> as a consequence of the XML attribute normalization
rules.</p><note><p>XML 1.0 did not permit
  an XML processor to normalize <char>U+0085</char> or <char>U+2028</char> characters 
  to a <char>U+000A</char> character.  However, if
a document entity that specifies version 1.1 invokes an external general
parsed entity with no text declaration or a text declaration that specifies
version 1.0, the external parsed entity is processed according to the rules
of XML 1.1.  For this reason, <char>U+0085</char> and <char>U+2028</char> characters in text and
attribute nodes <rfc2119>MUST</rfc2119> always be escaped using character references,
regardless of the value of the <code nobreak="false">version</code> parameter.
</p><p>
  XML 1.0 permitted control characters in the range <char>U+007F</char> through 
  <char>U+009F</char>
to appear as literal characters in an XML document, but XML 1.1
requires such characters, other than <char>U+0085</char>,
to be escaped as character references.  An
external general parsed entity with no text declaration or a text
declaration that specifies a version pseudo-attribute with value
<code nobreak="false">1.0</code> that is invoked by an XML 1.1 document entity
<rfc2119>MUST</rfc2119>
follow the rules of XML 1.1.  Therefore, the non-whitespace control
characters in the ranges <char>U+0001</char> through <char>U+001F</char> and <char>U+007F</char> through 
  <char>U+009F</char>
<rfc2119>MUST</rfc2119>
always be escaped, regardless of the value of the <code nobreak="false">version</code> parameter.
</p></note><p>It is a <termref def="serial-err">serialization error</termref> <errorref code="0004" class="PM"/> 
  to specify the <code nobreak="false">doctype-system</code> parameter, or to specify the <code nobreak="false">standalone</code> parameter 
  with a value other than <code nobreak="false">omit</code>, if the
  <termref def="dt-input-tree"/> contains text nodes or multiple element nodes as children
of the root node. The
<termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> either raise the error, or recover
by ignoring the request to output a document type declaration or
<code nobreak="false">standalone</code> parameter.</p><div2 id="XML_PARAMS"><head>The Influence of Serialization Parameters upon the XML Output Method</head><p>The serialization parameters that affect the XML output method are listed
    in the following subsections.</p><p>Serialization parameters other than those listed are not applicable to this output
    method.  It is the responsibility of the
    <termref def="host-language">host language</termref> to specify
    whether an error occurs if such a parameter is specified in combination
    with the XML output method, or whether the parameter is ignored, or whether
    it is validated and then ignored.</p><div3 id="XML_CANONICAL"><head>XML Output Method: the <code nobreak="false">canonical</code> Parameter</head><p>The <code nobreak="false">canonical</code> parameter specifies whether the XML output should be
      normalized to its canonical form, as specified by <bibref ref="canonical-xml-1-1"/>. The
      default value is <code nobreak="false">false</code>.</p><p>If the value is <code nobreak="false">false</code> this parameter has no effect on the output.</p><p>If the value is <code nobreak="false">true</code> then all parameters except the following are ignored:
              <code nobreak="false">normalization-form</code> and <code nobreak="false">media-type</code>.</p><p>The <termref def="serializer">serializer</termref>
            <rfc2119>MUST</rfc2119> serialize the normalized sequence according to the rules
            specified at <bibref ref="canonical-xml-1-1"/>, with the octet stream created by the
            encoding phase of serialization (<specref ref="serphases"/>) as the first parameter, and
            the second parameter (whether comments should be included) set to <code nobreak="false">true</code>. If
            comments are not desired, they should be removed before serialization. </p><note><p><bibref ref="canonical-xml-1-1"/> specifies a number of changes to the serialized
              output that are not otherwise discussed in these specifications, such as converting each
              empty element to a start-end tag pair, normalizing whitespace in start and end tags,
              serializing namespace axes before attribute axes, sorting namespace and attribute axes
              lexicographically, and dropping superfluous namespace declarations. Implementations
                <rfc2119>MUST</rfc2119> raise an error on documents containing relative namespace
              URIs, or on octet streams that do not contain a well-formed XML document.</p></note><p>A serialization error <errorref code="0024" class="RE"/> results if any error is raised during the 
        canonicalization process.</p></div3><div3 id="XML_VERSION"><head>XML Output Method: the <code nobreak="false">version</code> Parameter</head><p>The 
  <code nobreak="false">version</code> parameter specifies the version of XML
and the version of Namespaces in XML to
be used <phrase diff="chg" at="2023-11-01">in the serialized output</phrase>.
      The default value is <code nobreak="false">1.0</code>.
The version output in the XML declaration (if an XML declaration is not omitted) 
<rfc2119>MUST</rfc2119> correspond to the version of XML used by
the <termref def="serializer">serializer</termref>. The value of the
<code nobreak="false">version</code> parameter 
<rfc2119>MUST</rfc2119> match the
<xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-VersionNum" xlink:type="simple">VersionNum</xnt>
production of the XML Recommendation <bibref ref="xml"/> or <bibref ref="xml11"/>.
A serialization error <errorref code="0013" class="SU"/> results if the value of the <code nobreak="false">version</code> parameter specifies 
a version of XML that is not supported by the <termref def="serializer">serializer</termref>; 
the <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119>
raise the error.</p><!-- Start:  added for Bug 6732 --><p>This document provides the normative
definition of serialization for the XML output method if the
<code nobreak="false">version</code> parameter has either the value <code nobreak="false">1.0</code> or
<code nobreak="false">1.1</code>.  For
any other value of <code nobreak="false">version</code> parameter, the behavior is
<termref def="impdef">implementation-defined</termref>. 
In that case the <termref def="impdef">implementation-defined</termref>
behavior <rfc2119>MAY</rfc2119> supersede all other requirements of
this recommendation.</p><imp-def-feature>If an implementation
supports a value of the <code nobreak="false">version</code> parameter for the XML or XHTML
output method for which this document does not provide a normative definition,
the behavior is
<termref def="impdef">implementation-defined</termref>.</imp-def-feature><!-- End:  added for Bug 6732 --><p>If the serialized result would contain an
<xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="Names" ref="NT-NCName" xlink:type="simple">NCName</xnt> that contains a character that is not
permitted by the version of Namespaces in XML specified by the
<code nobreak="false">version</code> parameter, a <termref def="serial-err">serialization error</termref> <errorref code="0005" class="RE"/> results.
The <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.</p><p>If the serialized result would contain a character
that is not permitted by the version of XML specified by the
<code nobreak="false">version</code> parameter, a <termref def="serial-err">serialization error</termref> <errorref code="0006" class="RE"/> results.  The
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.</p><example><p>For example, if the <code nobreak="false">version</code>
  parameter has the value <code nobreak="false">1.0</code>, and the <termref def="dt-input-tree"/>
contains a non-whitespace control character in the range <char>U+0001</char> through
<char>U+001F</char>, a <termref def="serial-err">serialization error</termref> <errorref code="0006" class="RE"/> results.
If the <code nobreak="false">version</code> parameter has the value <code nobreak="false">1.1</code>
  and a comment node in the <termref def="dt-input-tree"/> contains a
  non-whitespace control character in the range <char>U+0001</char> through
  <char>U+001F</char> or a
  control character other than <char>U+0085</char> in the range <char>U+007F</char> through
  <char>U+009F</char>, a
<termref def="serial-err">serialization error</termref> <errorref code="0006" class="RE"/> results.</p></example></div3><div3 id="XML_ENCODING"><head>XML Output Method: the <code nobreak="false">encoding</code> Parameter</head><p>The <code nobreak="false">encoding</code> parameter specifies the
encoding to be used <phrase diff="chg" at="2023-11-01">in the serialized output</phrase>.
<termref def="serializer">Serializers</termref>
are <rfc2119>REQUIRED</rfc2119>  to support values of <code nobreak="false">UTF-8</code> and
<code nobreak="false">UTF-16</code>. A <termref def="serial-err">serialization error</termref> <errorref code="0007" class="SU"/> occurs if an output
encoding other than <code nobreak="false">UTF-8</code> or <code nobreak="false">UTF-16</code> is
requested and the <termref def="serializer">serializer</termref>
does not support that encoding. The <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error, or recover by using
<code nobreak="false">UTF-8</code> or <code nobreak="false">UTF-16</code> instead.
The <termref def="serializer">serializer</termref>
<rfc2119>MUST NOT</rfc2119> use an encoding whose name does not match the
<xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-EncName" xlink:type="simple">EncName</xnt>
production of the XML Recommendation <bibref ref="xml"/>.
</p><p>When outputting a newline character in the <termref def="dt-input-tree"/>, the
<termref def="serializer">serializer</termref> is free to represent it using any character sequence
that will be normalized to a newline character by an XML parser,
unless a specific mapping for the newline character is
provided in a character map (see <specref ref="character-maps"/>).</p><p>When outputting any other character that is defined in the
selected encoding, the character 
<rfc2119>MUST</rfc2119> be output
using the correct representation of that character in the selected encoding.</p><p>It is possible that the <termref def="dt-input-tree"/> will contain a character that
cannot be represented in the encoding that the <termref def="serializer">serializer</termref>
is using for output. In this case, if the character occurs in a context where XML
recognizes character references (that is, in the value of an attribute
node or text node), then the character <rfc2119>MUST</rfc2119> be output as a character
reference. A <termref def="serial-err">serialization error</termref> <errorref code="0008" class="RE"/> occurs if such a character appears in
a context where character references are not allowed (for example, if
the character occurs in the name of an element). The <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error.
</p><example><p>For example,
if a text node contains the character <char>U+00E9</char>,
and the value of the <code nobreak="false">encoding</code> parameter is
<code nobreak="false">US-ASCII</code>, the character <rfc2119>MUST</rfc2119> be serialized as a character
reference.  If a comment node contains the same character, a
<termref def="serial-err">serialization error</termref> <errorref code="0008" class="RE"/> results.
</p></example></div3><div3 id="xml-indent"><head>XML Output Method: the <code nobreak="false">indent</code> and <code nobreak="false">suppress-indentation</code> Parameters</head><!--Start of text changed for Bug 6808--><p>The <code nobreak="false">indent</code> and
<code nobreak="false">suppress-indentation</code> parameters control whether the
<termref def="serializer">serializer</termref> <rfc2119>MAY</rfc2119> adjust the whitespace
in the serialized result so that a person will find it easier to read.
If the <code nobreak="false">indent</code> parameter has 
the value <code nobreak="false">true</code>,
the <termref def="serializer">serializer</termref> <rfc2119>MAY</rfc2119> output whitespace characters in
  addition to the whitespace characters in the <termref def="dt-input-tree"/>.  
  It <rfc2119>MAY</rfc2119> also elide from the output whitespace
  characters that occurred in the <termref def="dt-input-tree"/> or replace
such whitespace characters with other whitespace characters.</p><!--Start of text changed for Bug 6808 under comment 12--><p>
<termdef term="content" id="content">The term <term>content</term> has the
same meaning as the term <xtermref spec="XML" ref="dt-content"/>
defined in <xspecref spec="XML" ref="sec-starttags"/> of
<bibref ref="xml"/>.</termdef>
<termdef term="immediate content" id="immediate-content">
The <term>immediate content</term> of an element is the part of the
<termref def="content">content</termref> of the element that is not
also in the <termref def="content">content</termref> of a child element
of that element.</termdef>
</p><!--End of text changed for Bug 6808 under comment 12--><p>If the
<code nobreak="false">indent</code> parameter has the value <code nobreak="false">false</code>, the
<termref def="serializer">serializer</termref> <rfc2119>MUST NOT</rfc2119> add, elide
or replace whitespace characters in the output. If the <code nobreak="false">indent</code> parameter has 
the value <code nobreak="false">true</code>,
the <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119>
use an algorithm for dealing with whitespace characters that satisfies
all of the following constraints.

<!--Start of text changed for Bug 6808 under comment 12-->
If more than one constraint applies,
the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> apply the most restrictive constraint.  That is, if
any applicable constraint indicates that whitespace 
<rfc2119>MUST NOT</rfc2119> be added, elided or replaced, that
constraint prevails; if an applicable constraint indicates that
whitespace <rfc2119>SHOULD NOT</rfc2119> be added, elided or replaced,
while all other applicable constraints indicate that whitespace
<rfc2119>MAY</rfc2119>
be added, elided or replaced, whitespace <rfc2119>SHOULD NOT</rfc2119>
be added, elided or replaced.

<!--End of text changed for Bug 6808 under comment 12-->
</p><ulist><item><p>Whitespace characters
<rfc2119>MAY</rfc2119>
be added adjacent to a text node
only
if the text node contains only whitespace characters.  Whitespace characters in
such a text node <rfc2119>MAY</rfc2119> also be elided or replaced.
For example, a tab <rfc2119>MAY</rfc2119> be inserted as a
replacement for existing spaces.</p></item><item><p>Whitespace characters
<rfc2119>MAY</rfc2119> be added, elided or replaced in the
<termref def="immediate-content">immediate content</termref> of an
element whose type annotation is <code nobreak="false">xs:untyped</code> or
<code nobreak="false">xs:anyType</code> and that has element node children, in the
<termref def="immediate-content">immediate content</termref> of an element whose content model
is element only, or outside
the <termref def="content">content</termref> of any element.</p></item><item><p>Whitespace characters
<rfc2119>MUST NOT</rfc2119> be added,
elided or replaced
in the <termref def="immediate-content">immediate content</termref> of an element
whose content model is 
known to be simple or
empty.</p></item><item><!--Text replaced by erratum E6 change 4"--><p>Whitespace characters 
<rfc2119>SHOULD NOT</rfc2119> be added,
elided or replaced
in places where the characters would
constitute significant whitespace, for example, in the
<termref def="immediate-content">immediate content</termref> of an element
that is annotated with a type
other than <code nobreak="false">xs:untyped</code> or <code nobreak="false">xs:anyType</code>, and
whose content model is known to be mixed.</p><!--End of text replaced by erratum E6--></item><item><p>Whitespace characters
<rfc2119>MUST NOT</rfc2119> be added,
elided or replaced
in the <termref def="content">content</termref>
of an element
whose expanded QName is a member of the list of expanded QNames in the
value of the <code nobreak="false">suppress-indentation</code> parameter.</p></item><!--End of text changed for Bug 6808--><item><p>Whitespace characters <rfc2119>MUST NOT</rfc2119> be
added, elided or replaced
in a part of the result document that is controlled by an
<code nobreak="false">xml:space</code> attribute with value <code nobreak="false">preserve</code>.
(See <bibref ref="xml"/> for more information about the
<code nobreak="false">xml:space</code> attribute.)
</p></item></ulist><note><p>The effect of these rules is to ensure that whitespace is
added in only those places where (a) XSLT’s <code nobreak="false">&lt;xsl:strip-space&gt;</code>
declaration could cause it to be removed, and
(b) it does not affect the <termref def="dt-string-value">string value</termref> of any element node with
simple content. It is usually not safe to indent document types that include elements
with mixed content.</p></note><note><p>The whitespace added may possibly
be based on whitespace stripped from either the source document or the
stylesheet (in the case of XSLT), or
guided by other means that might depend on the <termref def="host-language">host language</termref>,
  in the case of an <termref def="dt-input-tree"/> created using some other process.</p></note></div3><div3 id="XML_CDATA-SECTION-ELEMENTS"><head>XML Output Method: the <code nobreak="false">cdata-section-elements</code> Parameter</head><p>The <code nobreak="false">cdata-section-elements</code> parameter contains a list
of expanded QNames. If the expanded QName of the parent of a text node
is a member of the list, then the text node

<rfc2119>MUST</rfc2119> be output as a
CDATA section, except in those circumstances
described below.</p><p>If the text node contains the sequence of characters
<code nobreak="false">]]&gt;</code>, then the currently open CDATA section

<rfc2119>MUST</rfc2119> be
closed following the <code nobreak="false">]]</code> and a new CDATA section opened
before the <code nobreak="false">&gt;</code>.</p><p>If the text node contains characters that are not
representable in the character encoding being used 
  <phrase diff="chg" at="2023-11-01">in the serialized output</phrase>, 
  then the currently open CDATA section

<rfc2119>MUST</rfc2119> be closed
before such characters, the characters

<rfc2119>MUST</rfc2119> be output using
character references or entity references, and a new CDATA
section

<rfc2119>MUST</rfc2119> be opened for any further
characters in the text node.</p><p>CDATA sections 
<rfc2119>MUST NOT</rfc2119> be used except where they
have been explicitly requested by the user, either by using the
<code nobreak="false">cdata-section-elements</code> parameter, or by using some other
<termref def="impdef">implementation-defined</termref> mechanism.</p><note><p>This is phrased to permit an implementer to provide an option that
attempts to preserve CDATA sections present in the source
document.</p></note><imp-def-feature>A <termref def="serializer">serializer</termref> <rfc2119>MAY</rfc2119> provide an <termref def="impdef">implementation-defined</termref> mechanism to place CDATA sections in the <termref def="result-tree">result tree</termref>.</imp-def-feature></div3><div3 id="XML_OMIT-XML-DECLARATION"><head>XML Output Method: the <code nobreak="false">omit-xml-declaration</code> and <code nobreak="false">standalone</code> Parameters</head><p>The XML output method
<rfc2119>MUST</rfc2119> output an XML declaration if the <code nobreak="false">omit-xml-declaration</code> parameter has the value <code nobreak="false">false</code>.   
The XML declaration <rfc2119>MUST</rfc2119> include both version information and an encoding declaration. 
If the <code nobreak="false">standalone</code> parameter has 
the value <code nobreak="false">true</code> or <code nobreak="false">false</code>,
the XML declaration <rfc2119>MUST</rfc2119> include a standalone document declaration 
  with the value of the <code nobreak="false">standalone</code> parameter set accordingly to <code nobreak="false">yes</code> or <code nobreak="false">no</code>.
If the <code nobreak="false">standalone</code> parameter has
the value <code nobreak="false">omit</code>, the XML declaration
<rfc2119>MUST NOT</rfc2119> include a standalone document declaration; this ensures
that it is both an XML declaration (allowed at the beginning of a
document entity) and a text declaration (allowed at the beginning of
an external general parsed entity).</p><p>A <termref def="serial-err">serialization error</termref> <errorref code="0009" class="PM"/> results if the
<code nobreak="false">omit-xml-declaration</code> parameter has 
the value <code nobreak="false">true</code>, and</p><ulist><item><p>the <code nobreak="false">standalone</code> parameter has a value other than
<code nobreak="false">omit</code>; or
</p></item><item><p>the <code nobreak="false">version</code> parameter has a value other than
<code nobreak="false">1.0</code> and the <code nobreak="false">doctype-system</code>
parameter is specified.</p></item></ulist><p>The <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.
</p><p>Otherwise, if the
<code nobreak="false">omit-xml-declaration</code> parameter has 
the <code nobreak="false">true</code>,
 the XML output method

<rfc2119>MUST NOT</rfc2119> output an XML declaration.</p></div3><div3 id="XML_DOCTYPE"><head>XML Output Method: the <code nobreak="false">doctype-system</code> and <code nobreak="false">doctype-public</code> Parameters</head><p>If the <code nobreak="false">doctype-system</code> parameter is specified, the
XML output method 
<rfc2119>MUST</rfc2119> output a document type
declaration immediately before the first element. The name following
<code nobreak="false">&lt;!DOCTYPE</code> 
<rfc2119>MUST</rfc2119> be the name of the first element,
if any. If the <code nobreak="false">doctype-public</code> parameter is also specified, then the
XML output method <rfc2119>MUST</rfc2119> output <code nobreak="false">PUBLIC</code>
followed by the public identifier and then the system identifier;
otherwise, it <rfc2119>MUST</rfc2119> output <code nobreak="false">SYSTEM</code>
followed by the system
identifier. The internal subset 
<rfc2119>MUST</rfc2119> be empty. The
<code nobreak="false">doctype-public</code> parameter 
<rfc2119>MUST</rfc2119> be ignored unless the
<code nobreak="false">doctype-system</code> parameter is specified.</p></div3><div3 id="xml-undeclare-NS"><head>XML Output Method: the <code nobreak="false">undeclare-prefixes</code> Parameter</head><p>The Data Model allows an element
node that binds a non-empty prefix to
have a child element node that does
not bind that same prefix. In <emph>Namespaces in XML 1.1</emph> (<bibref ref="xml-names11"/>), this can be represented accurately by undeclaring
prefixes.  For the undeclaring prefix of the child element node,  
if the <code nobreak="false">undeclare-prefixes</code> parameter has 
the value <code nobreak="false">true</code>,
the output method is XML or XHTML, and the <code nobreak="false">version</code> 
parameter value is greater than <code nobreak="false">1.0</code>,
the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> undeclare its namespace.  If the
<code nobreak="false">undeclare-prefixes</code> parameter has the value <code nobreak="false">false</code> and the output method is XML or
XHTML, then the undeclaration of prefixes <rfc2119>MUST NOT</rfc2119> occur.</p><example><p>Consider an element <code nobreak="false">x:foo</code> with four in-scope namespaces
that associate prefixes with URIs as follows:
</p><ulist><item><p><code nobreak="false">x</code> is associated with
<code nobreak="false">http://example.org/x</code></p></item><item><p><code nobreak="false">y</code> is associated with
<code nobreak="false">http://example.org/y</code></p></item><item><p><code nobreak="false">z</code> is associated with
<code nobreak="false">http://example.org/z</code></p></item><item><p><code nobreak="false">xml</code> is associated with
<code nobreak="false">http://www.w3.org/XML/1998/namespace</code></p></item></ulist><p>Suppose that it has a child element <code nobreak="false">x:bar</code> with three in-scope namespaces:</p><ulist><item><p><code nobreak="false">x</code> is associated with
<code nobreak="false">http://example.org/x</code></p></item><item><p><code nobreak="false">y</code> is associated with
<code nobreak="false">http://example.org/y</code></p></item><item><p><code nobreak="false">xml</code> is associated with
<code nobreak="false">http://www.w3.org/XML/1998/namespace</code></p></item></ulist><p>If namespace undeclaration is in effect, it will be serialized this way:</p><eg xml:space="preserve">&lt;x:foo xmlns:x="http://example.org/x"
       xmlns:y="http://example.org/y"
       xmlns:z="http://example.org/z"&gt;
       
       &lt;x:bar xmlns:z=""&gt;...&lt;/x:bar&gt;
       
&lt;/x:foo&gt;</eg></example><p>In <emph>Namespaces in XML</emph> 1.0 (<bibref ref="xml-names"/>), prefix undeclaration is not possible.
If the output method is XML or XHTML, the value of the <code nobreak="false">undeclare-prefixes</code> parameter is 
<code nobreak="false">true</code>,
and the value of the <code nobreak="false">version</code> parameter is <code nobreak="false">1.0</code>,
a <termref def="serial-err">serialization error</termref> <errorref code="0010" class="PM"/> results; the
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.</p></div3><div3 id="XML_NORMALIZATION-FORM"><head>XML Output Method: the <code nobreak="false">normalization-form</code> Parameter</head><p>The <code nobreak="false">normalization-form</code> parameter is applicable to the XML output method.
The values <code nobreak="false">NFC</code> and <code nobreak="false">none</code> <rfc2119>MUST</rfc2119> be supported by the <termref def="serializer">serializer</termref>.
A <termref def="serial-err">serialization error</termref> <errorref code="0011" class="SU"/> results if the value of the
<code nobreak="false">normalization-form</code> parameter specifies a normalization form
that is not supported by the
<termref def="serializer">serializer</termref>; the
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the error.</p><p>The meanings associated with the possible values of
the <code nobreak="false">normalization-form</code> parameter are as follows:</p><ulist><item><p><code nobreak="false">NFC</code> specifies the serialized result will be
       in Normalization Form C, using the rules specified in <bibref ref="charmod-norm"/>.</p></item><item><p><code nobreak="false">NFD</code> specifies the serialized result will be
       in Normalization Form D, as specified in <bibref ref="UNICODE-NORMALIZATION-FORM"/>.</p></item><item><p><code nobreak="false">NFKC</code> specifies the serialized result will be
       in Normalization Form KC, as specified in <bibref ref="UNICODE-NORMALIZATION-FORM"/>.</p></item><item><p><code nobreak="false">NFKD</code> specifies the serialized result will be
       in Normalization Form KD, as specified in <bibref ref="UNICODE-NORMALIZATION-FORM"/>.</p></item><item><p><code nobreak="false">fully-normalized</code> specifies the serialized result
       will be in fully normalized text, as specified in <bibref ref="charmod-norm"/>.</p></item><item><p><code nobreak="false">none</code> specifies that no <termref def="unicode-normalization">Unicode Normalization</termref> will
       be applied.</p></item><item><p>An <termref def="impdef">implementation-defined</termref> value
       has an <termref def="impdef">implementation-defined</termref>
       effect.</p><imp-def-feature>If the value of the <code nobreak="false">normalization-form</code> form parameter is not <code nobreak="false">NFC</code>, <code nobreak="false">NFD</code>,
          <code nobreak="false">NFKC</code>, <code nobreak="false">NFKD</code>, <code nobreak="false">fully-normalized</code>,
           or <code nobreak="false">none</code> then the meaning of the value and its effect is
          <termref def="impdef">implementation-defined</termref>.</imp-def-feature></item></ulist><p>If the value of the parameter is <code nobreak="false">fully-normalized</code>, then no
<emph>relevant construct</emph> of the parsed entity created by the <termref def="serializer">serializer</termref>
may start with a composing character. The term <emph>relevant construct</emph>
has the meaning defined in section 2.13 of <bibref ref="xml11"/>. If this condition is not
satisfied, a <termref def="serial-err">serialization error</termref> <errorref code="0012" class="RE"/> <rfc2119>MUST</rfc2119> be raised.</p><note><p>Specifying <code nobreak="false">fully-normalized</code> as the value of this parameter
does not guarantee that the XML document output by the <termref def="serializer">serializer</termref> will in fact
be fully normalized as defined in <bibref ref="xml11"/>. This is because the <termref def="serializer">serializer</termref> does
not check that the text is <code nobreak="false">include normalized</code>, which would involve
checking all external entities that it refers to (such as an external DTD).
Furthermore, the <termref def="serializer">serializer</termref> does not check whether any character escape
generated using character maps represents a composing character.</p></note></div3><div3 id="XML_MEDIA-TYPE"><head>XML Output Method: the <code nobreak="false">media-type</code> Parameter</head><p>The <code nobreak="false">media-type</code> parameter is applicable to the
XML output method. 
See <specref ref="serparam"/> for more
information.</p></div3><div3 id="XML_USE-CHARACTER-MAPS"><head>XML Output Method: the <code nobreak="false">use-character-maps</code> Parameter</head><p>The <code nobreak="false">use-character-maps</code> parameter is applicable to the XML output method.
The result of serialization using the XML output method is not
guaranteed to be well-formed XML if character maps have been specified.
See <specref ref="character-maps"/> for more information.</p></div3><div3 id="XML_BYTE-ORDER-MARK"><head>XML Output Method: the <code nobreak="false">byte-order-mark</code> Parameter</head><p>The <code nobreak="false">byte-order-mark</code> parameter is
applicable to the XML output method.  See
<specref ref="serparam"/> for more information.</p><note><p>The byte order mark may be undesirable under certain circumstances, 
for example, to concatenate resulting XML fragments without additional processing to remove the byte order mark. 
Therefore this specification does not mandate the <code nobreak="false">byte-order-mark</code> parameter to have 
the value <code nobreak="false">true</code>
when the encoding is UTF-16, 
even though the XML 1.0 and XML 1.1 specifications state that entities encoded in UTF-16 <rfc2119>MUST</rfc2119> begin with a byte order mark.  
Consequently, this specification does not guarantee that the resulting XML fragment, 
without a byte order mark, will not cause an error when processed by a conforming XML processor.</p></note></div3><div3 id="XML_ITEM-SEPARATOR"><head>XML Output Method: the <code nobreak="false">item-separator</code> Parameter</head><p>The effect of the <code nobreak="false">item-separator</code> serialization parameter
is described in <specref ref="serdm"/>.</p></div3></div2></div1><div1 id="xhtml-output"><head>XHTML Output Method</head><changes><change issue="318" PR="342" date="2023-02-14">In the HTML and XHTML output methods, the rules for adding and replacing
      <code nobreak="false">meta</code> elements have been revised to take account of the new HTML5 syntax,
      for example <code nobreak="false">&lt;meta charset="UTF-8"&gt;</code>.
    </change><change issue="1889" PR="1977" date="2025-05-02">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.</change></changes><p>The XHTML output method serializes the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> as
XML, using the HTML compatibility guidelines defined in the XHTML
specification
(<bibref ref="xhtml1"/>
or the XHTML syntax of HTML5
(see <bibref ref="html5"/>).</p><p>The default value of the <code nobreak="false">html-version</code> serialization parameter for this method
  is <code nobreak="false">5.0</code>, and all references to the value of this parameter assume this default when
  the parameter is absent. The value of the parameter is a decimal, so the values <code nobreak="false">5</code>
  and <code nobreak="false">5.0</code> are equivalent.</p><p><termdef id="id-with-html5" term="with HTML5">The term <term>with HTML5</term> is used
  in this specification to qualify rules that apply only when the effective version of the
  <code nobreak="false">html-version</code> serialization parameter is <code nobreak="false">5.0</code>.</termdef></p><p><termdef id="id-prior-to-html5" term="prior to HTML5">The term <term>prior to HTML5</term> is used
  in this specification to qualify rules that apply only when the effective version of the
  <code nobreak="false">html-version</code> serialization parameter is less than <code nobreak="false">5.0</code>.</termdef></p><p>
<termdef id="recognized-as-HTML" term="recognized as an HTML element" open="true">An element node is <term>recognized as an
HTML element</term> by the XHTML output method if either of the following conditions is true:</termdef>
</p><ulist><item><p>the element node is in the
<termref def="xhtml-namespace">XHTML namespace</termref>; or</p></item><item><p><termref def="id-with-html5">With HTML5</termref>: the element has a
<termref def="null-namespace-URI">null namespace URI</termref> and
the local part of the name is equal
to the name of an element defined by HTML5 <bibref ref="html5"/>,
making the comparison
<termref def="caseless-compare">without regard to case</termref>.</p></item></ulist><p role="closetermdef"/><p>It is entirely the responsibility of the
  supplier of the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>
to ensure that it conforms to the relevant specification, this being:</p><ulist><item><p><termref def="id-with-html5">With HTML5</termref>, the XHTML syntax of HTML5;</p></item><item><p><termref def="id-prior-to-html5">Prior to HTML5</termref>, the <bibref ref="xhtml1"/> or
<bibref ref="xhtml11"/> specification.</p></item></ulist><p>It is not an error if the
<termref def="dt-input-tree"/> is invalid XHTML. Equally, it is entirely under the
control of the supplier of the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
  whether the output conforms to XHTML 1.0
Strict, XHTML 1.0 Transitional,
the XHTML syntax of HTML5 (see
<bibref ref="html5"/>),
<bibref ref="html-polyglot"/>
or any other specific definition of XHTML.</p><p>The serialization of the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> follows the same rules as for
the XML output method, with the general exceptions noted below and parameter-specific exceptions in <specref ref="XHTML_PARAMS"/>.
These differences are based on the HTML compatibility guidelines
published in Appendix C of <bibref ref="xhtml1"/>
and on <bibref ref="html-polyglot"/>,
both of which are designed
to ensure that as far as possible, XHTML is rendered correctly on user
agents designed originally to handle HTML.</p><p><termref def="id-with-html5">With HTML5</termref> the 
  <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> is first subjected to
<termref def="PREFIXNORMALIZATION">prefix normalization</termref>.</p><p>
<termdef term="prefix normalization" id="PREFIXNORMALIZATION">During
  <term>prefix normalization</term>, any element node in the 
  <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> that is in one of the
<termref def="xhtml-namespace">XHTML namespace</termref>, the
<termref def="svg-namespace">SVG namespace</termref> or the
<termref def="mathml-namespace">MathML namespace</termref> has its name
replaced by the local part of its name.  Such an element node is given a
default namespace node whose value is the element’s namespace URI.  Any
namespace node for any of those three namespaces that was previously present
on any element node in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> is also removed,
unless the prefix that that namespace node declared is used as the prefix on
the name of an attribute on that element or an ancestor of that
element.</termdef></p><p>
The process of <termref def="PREFIXNORMALIZATION">prefix normalization</termref>

  is equivalent to replacing the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
  with the result of the transformation described by this XSLT
  stylesheet, with the root of the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> as the initial <phrase diff="chg" at="2023-10-30">context value</phrase>.

</p><eg xml:space="preserve">
&lt;xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="4.0"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns:mathml="http://www.w3.org/1998/Math/MathML"&gt;
  &lt;xsl:template match="xhtml:*|svg:*|mathml:*"&gt;
    &lt;xsl:element name="{local-name()}" 
                 namespace="{namespace-uri()}"&gt;
      &lt;xsl:apply-templates select="@*|namespace::*|node()"/&gt;
    &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="node()|@*|namespace::*"&gt;
    &lt;xsl:copy copy-namespaces="no"&gt;
      &lt;xsl:apply-templates select="@*|namespace::*|node()"/&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template
    match="namespace::*[. eq 'http://www.w3.org/1999/xhtml']|
           namespace::*[. eq 'http://www.w3.org/2000/svg']|
           namespace::*[. eq 'http://www.w3.org/1998/Math/MathML']"/&gt;
&lt;/xsl:stylesheet&gt;
</eg><!--
   - Commented out XQuery version, as it's using the namespace axis, which
   - isn't allowed in XQuery!
  --><!--
<p>
It is also equivalent to replacing the instance of the data model that is
to be serialized with the result of executing the following XQuery expression,
again with the instance of the data model as the context item.
</p>
<eg><![CDATA[
declare copy-namespaces preserve, no-inherit;

declare variable $ns-to-strip :=
                   ('http://www.w3.org/1999/xhtml',
                    'http://www.w3.org/2000/svg',
                    'http://www.w3.org/1998/Math/MathML');

declare function local:copy($n as node()) {
  typeswitch ($n)
    case $d as document-node()
      return document { $d/node()/local:copy(.) }
    case $e as element()
      return element { if (namespace-uri($e) = $ns-to-strip)
                       then QName(namespace-uri($e),local-name($e))
                       else node-name($e) }
                { $e/(@*,namespace::*,node())/local:copy(.) }
    case $ns as namespace-node()
      return if (fn:data($ns) = $ns-to-strip)
             then ()
             else $ns
    default
      return $n
};

local:copy(.)
]]></eg>
--><!--
<edtext>Serialization has always referred
to the XHTML namespace (and the XML namespace, for that matter), but has
never provided a definition or reference.  Must rectify that.</edtext></ednote>
--><ulist><item><p><termdef term="EMPTY" id="XHTMLEMPTY">The following XHTML elements have an <term>EMPTY</term> content model: <code nobreak="false">area</code>, <code nobreak="false">base</code>, <code nobreak="false">br</code>, <code nobreak="false">col</code>, <code nobreak="false">embed</code>, <code nobreak="false">hr</code>, <code nobreak="false">img</code>, <code nobreak="false">input</code>, <code nobreak="false">link</code>, <code nobreak="false">meta</code>, <code nobreak="false">basefont</code>, <code nobreak="false">frame</code>,  <code nobreak="false">isindex</code>, and <code nobreak="false">param</code>.</termdef>
<termdef term="void" id="XHTMLVOID">The
<term>void</term> elements of HTML5 are
<code nobreak="false">area</code>, <code nobreak="false">base</code>,
<code nobreak="false">br</code>, <code nobreak="false">col</code>, <code nobreak="false">embed</code>,
<code nobreak="false">hr</code>, <code nobreak="false">img</code>, <code nobreak="false">input</code>,
<code nobreak="false">keygen</code>, <code nobreak="false">link</code>, <code nobreak="false">meta</code>,
<code nobreak="false">param</code>, <code nobreak="false">source</code>, <code nobreak="false">track</code> and
<code nobreak="false">wbr</code>.</termdef></p><!-- Start of text added for bug 20245 --><p><termdef term="expected-empty" id="XHTMLEXPECTEDEMPTY" open="true">An element node is <term>expected to be empty</term> if
it is <termref def="recognized-as-HTML">recognized as an HTML element</termref>
and:</termdef></p><ulist><item><p><termref def="id-with-html5">With HTML5</termref>, the element is a <termref def="XHTMLVOID">void</termref>
element.</p></item><item><p><termref def="id-prior-to-html5">Prior to HTML5</termref>, the content model is
<termref def="XHTMLEMPTY">EMPTY</termref>.</p></item></ulist><p role="closetermdef"/><!-- End of text added for bug 20245 --><p>
If an element node that has no
child nodes is

<!-- Start of text added for bug 20245 -->
not
<termref def="XHTMLEXPECTEDEMPTY">expected to be empty</termref>, and:
<!-- End of text added for bug 20245 -->
</p><ulist><item><p><termref def="id-with-html5">With HTML5</termref>, the
HTML element is not a <termref def="XHTMLVOID">void</termref> element, or
</p></item><item><p>
<termref def="id-prior-to-html5">Prior to HTML5</termref>, the
content model of the HTML element
is not <termref def="XHTMLEMPTY">EMPTY</termref>
(for example, an empty title or paragraph)</p></item></ulist><p>
then the <termref def="serializer">serializer</termref> 
<rfc2119>MUST NOT</rfc2119> use the minimized form.
That is, it 
<rfc2119>MUST</rfc2119>
output <code nobreak="false">&lt;p&gt;&lt;/p&gt;</code> and not
<code nobreak="false">&lt;p /&gt;</code>. </p></item><item><!--Text replaced by erratum E7 change 1"--><p>If an element that has no
children is 
<!-- Start of text added for bug 20245 -->
<termref def="XHTMLEXPECTEDEMPTY">expected to be empty</termref>,
<!-- End of text added for bug 20245 -->
the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> use the minimized tag syntax,
for example
<code nobreak="false">&lt;br /&gt;</code>, as the alternative syntax
<code nobreak="false">&lt;br&gt;&lt;/br&gt;</code> allowed by XML gives uncertain
results in many
legacy
user agents.
If the
<code nobreak="false">html-version</code>
serialization parameter has a value
less than <code nobreak="false">5.0</code>,
the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> include a
space before the trailing <code nobreak="false">/&gt;</code>, e.g.
<code nobreak="false">&lt;br /&gt;</code>, <code nobreak="false">&lt;hr /&gt;</code> and
<code nobreak="false">&lt;img src="karen.jpg" alt="Karen" /&gt;</code>.
</p><!--End of text replaced by erratum E7--></item><item><p>
<termref def="id-prior-to-html5">Prior to HTML5</termref>, the <termref def="serializer">serializer</termref> 
<rfc2119>MUST NOT</rfc2119> use the entity reference <code nobreak="false">&amp;apos;</code> which, although
defined in XML and therefore in XHTML, is not defined in
versions of HTML prior to HTML5, and is not recognized by all HTML user agents.</p></item><item><p><termref def="id-with-html5">With HTML5</termref>, the <termref def="serializer">serializer</termref> <rfc2119>SHOULD</rfc2119>
output namespace declarations in a way that is consistent with the requirements
of <bibref ref="html-polyglot"/>.</p><p><termref def="id-prior-to-html5">Prior to HTML5</termref>,
the <termref def="serializer">serializer</termref> <rfc2119>SHOULD</rfc2119> output namespace declarations
in a way that is consistent with the requirements of the XHTML DTD if this is
possible. </p><p>The XHTML 1.0 DTDs require the declaration
<code nobreak="false">xmlns="http://www.w3.org/1999/xhtml"</code>
to appear on the <code nobreak="false">html</code> element, and only on the <code nobreak="false">html</code> element.
The <bibref ref="html-polyglot"/> specification permits namespace declarations
to appear in a conforming document, but 
restricts the elements on which they can appear.
The <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> output namespace declarations that are consistent with
the namespace nodes present in the <termref def="result-tree">result tree</termref>, but it <rfc2119>MUST</rfc2119> avoid outputting
redundant namespace declarations on elements where the DTD would make them invalid,
for versions prior to HTML5, or where they
are not permitted by
<bibref ref="html-polyglot"/>,
for serialization according to the syntax of HTML5.</p><note><p>If the <code nobreak="false">html</code> element is generated by an XSLT literal result element of
the form <code nobreak="false">&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; ... &lt;/html&gt;</code>, or by an
XQuery direct element constructor of the same form, then the <code nobreak="false">html</code> element in
the result document will have a node name whose prefix is "", which will
satisfy the requirements of the DTD. In other cases the prefix assigned to
the element is implementation-dependent.</p></note></item></ulist><note><p><bibref ref="html-polyglot"/>
and Appendix C of <bibref ref="xhtml1"/>
describe
a number of compatibility guidelines for users of XHTML who wish to
render their XHTML documents with HTML user agents.  In some cases, such
as the guideline on the form empty elements
take, only the
serialization process itself has the ability to follow the guideline.  In
such cases, those guidelines are reflected in the requirements on the
<termref def="serializer">serializer</termref>
described above.</p><p>In all other cases, the guidelines can be
  adhered to by the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>.  
  The guideline on the use of whitespace characters in attribute
values is one such example.  Another example is that <code nobreak="false">xml:lang="..."</code> does not serialize to both <code nobreak="false">xml:lang="..."</code> and <code nobreak="false">lang="..."</code> as required by some legacy user agents.  It is the responsibility of the person or
process that creates the instance of the data model that is input to the
serialization process to ensure it is created in a way that is consistent
with the guidelines.  No <termref def="serial-err">serialization error</termref> results if the 
  <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> does not adhere to the guidelines.</p></note><div2 id="XHTML_PARAMS"><head>The Influence of Serialization Parameters upon the XHTML Output Method</head><p>The serialization parameters that affect the XHTML output method are listed
    in the following subsections.</p><p>Serialization parameters other than those listed are not applicable to this output
    method.  It is the responsibility of the
    <termref def="host-language">host language</termref> to specify
    whether an error occurs if such a parameter is specified in combination
    with the XHTML output method, or whether the parameter is ignored, or whether
    it is validated and then ignored.</p><div3 id="XHTML_CANONICAL"><head>XHTML Output Method: the <code nobreak="false">canonical</code> Parameter</head><p>The <code nobreak="false">canonical</code> parameter specifies whether the XHTML output should be
        normalized to its canonical form, as specified by <bibref ref="canonical-xml-1-1"/>. The
        default value is <code nobreak="false">false</code>.</p><p>If the value is <code nobreak="false">false</code> this parameter has no effect on the output.</p><p>If the value is <code nobreak="false">true</code> then all parameters except the following are ignored:
              <code nobreak="false">normalization-form</code>, <code nobreak="false">html-version</code>, <code nobreak="false">media-type</code>,
              and <code nobreak="false">include-content-type</code>.</p><p>The <termref def="serializer">serializer</termref>
            <rfc2119>MUST</rfc2119> serialize the normalized sequence according to the rules
            specified at <bibref ref="canonical-xml-1-1"/>, with the octet stream created by the
            encoding phase of serialization (<specref ref="serphases"/>) as the first parameter, and
            the second parameter (whether comments should be included) set to <code nobreak="false">true</code>. If
            comments are not desired, they should be removed before serialization. </p><note><p><bibref ref="canonical-xml-1-1"/> specifies a number of changes to the serialized
              output that are not otherwise discussed in these specifications, such as converting each
              empty element to a start-end tag pair, normalizing whitespace in start and end tags,
              serializing namespace axes before attribute axes, sorting namespace and attribute axes
              lexicographically, and dropping superfluous namespace declarations. Implementations
                <rfc2119>MUST</rfc2119> raise an error on documents containing relative namespace
              URIs, or on octet streams that do not contain a well-formed XML document.</p></note><p>A serialization error <errorref code="0024" class="RE"/> results if any error is raised during the 
        canonicalization process.</p></div3><div3 id="XHTML_VERSION"><head>XHTML Output Method: the <code nobreak="false">version</code>
Parameter</head><p>The behavior for the <code nobreak="false">version</code>
parameter for the XHTML output method is described in
<specref ref="XML_VERSION"/>. Note that this affects the version of XML used, not the version of HTML.</p></div3><div3 id="XHTML_HTML_VERSION"><head>XHTML Output Method: the <code nobreak="false">html-version</code> Parameter</head><p>The <code nobreak="false">html-version</code> parameter specifies whether the XHTML
output method will produce a serialized document following rules that
are tailored to the requirements of the XHTML syntax of <bibref ref="html5"/>,
or to the requirements of <bibref ref="xhtml1"/> and <bibref ref="xhtml11"/>.</p><p>The differences are described in detail throughout
<specref ref="xhtml-output"/>.</p></div3><div3 id="XHTML_ENCODING"><head>XHTML Output Method: the <code nobreak="false">encoding</code> Parameter</head><p>The behavior for <code nobreak="false">encoding</code> parameter for the XHTML output method is described in <specref ref="XML_ENCODING"/>.</p></div3><div3 id="XHTML_INDENT"><head>XHTML Output Method: the <code nobreak="false">indent</code> and <code nobreak="false">suppress-indentation</code> Parameters</head><!--Text replaced by erratum E9 change 1"--><p>If the <code nobreak="false">indent</code> parameter has 
the value <code nobreak="false">true</code>, the
<termref def="serializer">serializer</termref> <rfc2119>MAY</rfc2119> add or remove whitespace as it serializes the
<termref def="result-tree">result tree</termref>,
if it observes the following constraints.</p><ulist><item><p>Whitespace <rfc2119>MUST NOT</rfc2119> be added other than before or
after an element, or adjacent to an existing whitespace character.</p></item><item><p>Whitespace <rfc2119>MUST NOT</rfc2119> be added or removed adjacent to
an inline element. The inline elements are those elements
<termref def="recognized-as-HTML">recognized
as HTML elements</termref> that are
in the <code nobreak="false">%inline</code> category of any of the XHTML 1.0 DTDs, in the
<code nobreak="false">%inline.class</code> category of the XHTML 1.1 DTD,
those elements defined to be phrasing
elements in HTML5
 and elements
<termref def="recognized-as-HTML">recognized
as HTML elements</termref>
with local names <code nobreak="false">ins</code> and <code nobreak="false">del</code> if they are used as
inline elements (i.e., if they do not contain element children).</p></item><item><p>Whitespace <rfc2119>MUST NOT</rfc2119> be added or removed inside a
formatted element, the formatted elements being those
<termref def="recognized-as-HTML">recognized
as HTML elements</termref>
with local names <code nobreak="false">pre</code>, <code nobreak="false">script</code>, <code nobreak="false">style</code>,
<code nobreak="false">title</code>, and
    <code nobreak="false">textarea</code>.
</p></item><item><p>Whitespace characters
<rfc2119>MUST NOT</rfc2119> be added in the content of an element
whose expanded QName matches a member of the list of expanded QNames in the
value of the <code nobreak="false">suppress-indentation</code> parameter.
The expanded QName of an element node is considered to match a member of the list of expanded QNames
if:</p><ulist><item><p>the two expanded QNames are equal; or</p></item><item><p>the expanded QNames both have <termref def="null-namespace-URI">null
namespace URIs</termref>, and the local parts of the two QNames are
equal <termref def="caseless-compare">without regard to case</termref>; or
</p></item><item><p>the value of the
<code nobreak="false">html-version</code>
serialization parameter is
<code nobreak="false">5.0</code>, the local parts of the two QNames are equal
<termref def="caseless-compare">without regard to case</termref>
and one QName has a <termref def="null-namespace-URI">null namespace
URI</termref> and the namespace URI of the other is equal to the
<termref def="xhtml-namespace">XHTML namespace</termref> URI.</p></item></ulist></item></ulist><!--End of text replaced by erratum E9--><note><!--Text replaced by erratum E9 change 2"--><p>The effect of the above constraints is to
ensure any insertion or deletion of whitespace would not affect how
an
HTML user agent
that conforms to the specified version
of HTML
would render the output, assuming the serialized document does
not refer to any HTML style sheets.</p><!--End of text replaced by erratum E9--><p>The HTML definition of whitespace is different from the XML
  definition: see section 9.1 of  <bibref ref="html401"/> 4.01 specification.</p></note></div3><div3 id="XHTML_CDATA-SECTION-ELEMENTS"><head>XHTML Output Method: the <code nobreak="false">cdata-section-elements</code> Parameter</head><p>The behavior for <code nobreak="false">cdata-section-elements</code> parameter for the XHTML output method is described in <specref ref="XML_CDATA-SECTION-ELEMENTS"/>.</p></div3><div3 id="XHTML_OMIT-XML-DECLARATION"><head>XHTML Output Method: the <code nobreak="false">omit-xml-declaration</code> and <code nobreak="false">standalone</code> Parameters</head><p>The behavior for <code nobreak="false">omit-xml-declaration</code> and  <code nobreak="false">standalone</code> parameters for the XHTML output method is described in <specref ref="XML_OMIT-XML-DECLARATION"/>.</p><note><p>As with the XML output method, the XHTML
output method specifies that an XML declaration will be output unless it is suppressed using
the <code nobreak="false">omit-xml-declaration</code> parameter. Appendix C.1 of 
<bibref ref="xhtml1"/>
provides advice on the consequences of including,
or omitting, the XML declaration.</p></note></div3><div3 id="XHTML_DOCTYPE"><head>XHTML Output Method: the <code nobreak="false">doctype-system</code> and <code nobreak="false">doctype-public</code> Parameters</head><p><termref def="id-with-html5">With HTML5</termref>, if the
<!-- Start of text removed in response to bug 20264 -->
<!-- <code>doctype-public</code> and <code>doctype-system</code>
serialization parameters are both -->
<!-- End of text removed in response to bug 20264 -->
<!-- Start of text added in response to bug 20264 -->
<code nobreak="false">doctype-system</code> serialization parameter is
<!-- End of text added in response to bug 20264 -->
absent,
the first element node child of
the document node that is to be serialized
is
<termref def="recognized-as-HTML">recognized as an HTML
element</termref>, the local part of the QName of which is equal to
the string <code nobreak="false">HTML</code>,
<termref def="caseless-compare">without regard to case</termref>,
and any text node preceding that
element in document order contains only whitespace characters,
then
the XHTML output method <rfc2119>MUST</rfc2119> output a document type
declaration immediately before the first element, with no public or
system identifier.  The name following <code nobreak="false">&lt;!DOCTYPE</code>
<rfc2119>MUST</rfc2119>
be the same as the local part of the
name of the element.</p><p>Otherwise, the behavior for <code nobreak="false">doctype-system</code> and  <code nobreak="false">doctype-public</code> parameters for the XHTML output method is described in <specref ref="XML_DOCTYPE"/>.</p></div3><div3 id="XHTML_UNDECLARE-PREFIXES"><head>XHTML Output Method: the <code nobreak="false">undeclare-prefixes</code> Parameter</head><p>The behavior for <code nobreak="false">undeclare-prefixes</code> parameter for the XHTML output method is described in <specref ref="xml-undeclare-NS"/>.</p></div3><div3 id="XHTML_NORMALIZATION-FORM"><head>XHTML Output Method: the <code nobreak="false">normalization-form</code> Parameter</head><p>The behavior for <code nobreak="false">normalization-form</code> parameter for the XHTML output method is described in <specref ref="XML_NORMALIZATION-FORM"/>.</p></div3><div3 id="XHTML_MEDIA-TYPE"><head>XHTML Output Method: the <code nobreak="false">media-type</code> Parameter</head><p>The behavior for <code nobreak="false">media-type</code> parameter for the XHTML output method is described in <specref ref="XML_MEDIA-TYPE"/>.</p></div3><div3 id="XHTML_USE-CHARACTER-MAPS"><head>XHTML Output Method: the <code nobreak="false">use-character-maps</code> Parameter</head><p>The behavior for <code nobreak="false">use-character-maps</code> parameter for the XHTML output method is described in <specref ref="XML_USE-CHARACTER-MAPS"/>.</p></div3><div3 id="XHTML_BYTE-ORDER-MARK"><head>XHTML Output Method: the <code nobreak="false">byte-order-mark</code> Parameter</head><p>The behavior for <code nobreak="false">byte-order-mark</code> parameter for the XHTML output method is described in <specref ref="XML_BYTE-ORDER-MARK"/>.</p></div3><div3 id="XHTML_ESCAPE-URI-ATTRIBUTES"><head>XHTML Output Method: the <code nobreak="false">escape-uri-attributes</code> Parameter</head><p>

If the <code nobreak="false">escape-uri-attributes</code> parameter has
the value <code nobreak="false">true</code>,
 the XHTML output method 
<rfc2119>MUST</rfc2119> apply <termref def="uri-escaping">URI escaping</termref> to 
<termref def="uri-attribute-values">URI attribute values</termref>, except that relative URIs <rfc2119>MUST NOT</rfc2119> be absolutized.</p><note><p>This escaping is deliberately confined to non-ASCII characters,
because escaping of ASCII characters is not always appropriate, for
example when URIs or URI fragments are interpreted locally by the HTML
user agent. Even in the case of non-ASCII characters, escaping can
sometimes cause problems. More precise control of <termref def="uri-escaping">URI escaping</termref> is
therefore available by setting <code nobreak="false">escape-uri-attributes</code> to
<code nobreak="false">false</code>, and controlling the escaping of URIs by using methods defined in
<xspecref spec="FO40" ref="func-encode-for-uri"/> and <xspecref spec="FO40" ref="func-iri-to-uri"/>.</p></note></div3><div3 id="XHTML_INCLUDE-CONTENT-TYPE"><head>XHTML Output Method: the <code nobreak="false">include-content-type</code> Parameter</head><p>If the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> includes a <code nobreak="false">head</code> element
<termref def="recognized-as-HTML">recognized as
an HTML element</termref>,
and the <code nobreak="false">include-content-type</code> parameter has 
the value <code nobreak="false">true</code>,
the XHTML output method
<rfc2119>MUST</rfc2119>
add a <code nobreak="false">meta</code> element as the first child element of the
<code nobreak="false">head</code> element, specifying the character encoding actually
used. The <code nobreak="false">meta</code> element <rfc2119>SHOULD</rfc2119>
 be in no namespace if the <code nobreak="false">head</code> element is in no namespace, and in the XHTML namespace if the 
 <code nobreak="false">head</code> element is in the XHTML namespace.
</p><p><termref def="id-prior-to-html5">Prior to HTML5</termref>, the generated <code nobreak="false">meta</code>
  element <rfc2119>MUST</rfc2119> take the form shown below (assuming encoding <code nobreak="false">EUC-JP</code>):</p><eg xml:space="preserve">&lt;head&gt;
&lt;meta http-equiv="Content-Type" 
      content="text/html; charset=EUC-JP" /&gt;
...</eg><p><termref def="id-with-html5">With HTML5</termref>, the generated <code nobreak="false">meta</code>
  element <rfc2119>MUST</rfc2119> take the form shown below (again assuming encoding <code nobreak="false">EUC-JP</code>):</p><eg xml:space="preserve">&lt;head&gt;
&lt;meta charset="EUC-JP"/&gt;
...</eg><p>The content type<phrase diff="add" at="2023-02-09">, when included,</phrase> 
    <rfc2119>SHOULD</rfc2119> be set to the value given for the
<code nobreak="false">media-type</code> parameter.</p><note><p>It is recommended that the <termref def="host-language">host language</termref> use as default
value for this parameter one of the MIME types (<bibref ref="RFC2046"/>) registered for
XHTML. Currently, these are <code nobreak="false">text/html</code> (registered by <bibref ref="RFC2854"/>)
and <!--Text replaced by erratum E3 change 1"--><code nobreak="false">application/xhtml+xml</code><!--End of text replaced by erratum E3--> (registered by <bibref ref="RFC3236"/>). Note that
some user agents fail to recognize the charset parameter if the
content type is not <code nobreak="false">text/html</code>.</p></note><p>If a <code nobreak="false">meta</code> element has been added to the <code nobreak="false">head</code> element as described above,
then any existing <code nobreak="false">meta</code> element child of the <code nobreak="false">head</code> element having 
  <phrase diff="add" at="2023-02-09">either a <code nobreak="false">charset</code> attribute, or </phrase>
  an <code nobreak="false">http-equiv</code> attribute with the value "Content-Type",
making the comparison
<!-- Start of changes for Bug 8651 (Erratum SE.E17) -->
<termref def="caseless-compare">without regard to case</termref>
after first stripping leading and trailing spaces from the value of
the attribute solely for the purposes of comparison,
<!-- End of changes for Bug 8651 (Erratum SE.E17) -->
<rfc2119>MUST</rfc2119> be discarded. </p><note><p>This process removes possible parameters in the attribute value.  For example,</p><eg xml:space="preserve">&lt;meta http-equiv="Content-Type" 
      content="text/html;version='4.0'" /&gt;</eg><p>in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
    <phrase diff="chg" at="2023-02-09">might</phrase> be replaced by</p><eg xml:space="preserve" diff="add" at="2023-02-09">&lt;meta charset="UTF-8"/&gt;</eg></note></div3><div3 id="XHTML_ITEM-SEPARATOR"><head>XHTML Output Method: the <code nobreak="false">item-separator</code> Parameter</head><p>The effect of the <code nobreak="false">item-separator</code> serialization parameter
is described in <specref ref="serdm"/>.</p></div3></div2></div1><div1 id="html-output"><head>HTML Output Method</head><changes><change issue="318" PR="342" date="2023-02-14">In the HTML and XHTML output methods, the rules for adding and replacing
      <code nobreak="false">meta</code> elements have been revised to take account of the new HTML5 syntax,
      for example <code nobreak="false">&lt;meta charset="UTF-8"&gt;</code>.</change><change issue="1889" PR="1977" date="2025-05-02">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.</change></changes><p>The HTML output method serializes
  the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> as
HTML.</p><example><p>For example, the following XSL stylesheet generates html output,</p><eg xml:space="preserve">&lt;xsl:stylesheet version="2.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
&lt;xsl:output method="html" version="4.0"/&gt;
&lt;xsl:template match="/"&gt;
  &lt;html&gt;
    &lt;xsl:apply-templates/&gt;
  &lt;/html&gt;
&lt;/xsl:template&gt;
...
&lt;/xsl:stylesheet&gt;</eg></example><p>In the example, the <code nobreak="false">version</code> attribute of the <code nobreak="false">xsl:output</code> element indicates the version of the HTML Recommendation <bibref ref="html401"/> to which the serialized result is to conform.</p><p><termdef id="req-html-ver" term="requested HTML version">The <term>requested HTML version</term> is the
    value of the <code nobreak="false">html-version</code> serialization parameter if present; otherwise the value of the
    <code nobreak="false">version</code> serialization parameter if present; otherwise <code nobreak="false">5.0</code>.</termdef></p><p>This document provides the normative
definition of serialization for the HTML output method if the
<termref def="req-html-ver">requested HTML version</termref>
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
<termref def="impdef">implementation-defined</termref>.
In that case the
<termref def="impdef">implementation-defined</termref>
behavior <rfc2119>MAY</rfc2119> supersede all other requirements
of this recommendation.</p><imp-def-feature>If an implementation
supports a value of the <code nobreak="false">version</code> parameter for the HTML output
method for which this document does not provide a normative definition, the
behavior is <termref def="impdef">implementation-defined</termref>.</imp-def-feature><!-- End:  added for Bug 6732 --><p>An implementation is required to behave as specified in this document when the requested
  version is <code nobreak="false">5.0</code>. If the requested version is greater than or equal to <code nobreak="false">1</code>
  but less than <code nobreak="false">5.0</code>, then the processor <rfc2119>may</rfc2119> behave as if the
  requested version were <code nobreak="false">5.0</code>.</p><p>It is entirely the responsibility of the supplier of
  the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> to ensure that it conforms to the relevant HTML specification. 
  It is not an error if the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> is invalid HTML. 
  Equally, it is entirely under the control of the supplier of the
  <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> whether the output conforms to HTML.
<!--Start of text added for Bug 6723-->
If the result tree is valid HTML, the
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> serialize the result in a way that
conforms with the <termref def="req-html-ver">requested HTML version</termref>.</p><!--End of text added for Bug 6723--><div2 id="HTML_MARKUP"><head>Markup for Elements</head><p>As described in detail below,
the HTML output method
will not
output an element
differently from the XML output method unless the
element is to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref>.</p><p><termdef id="XML-ISLAND" term="XML Island">The
portion of the serialized document representing the result of serializing an element
that is not to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref> is known as an <term>XML Island.</term></termdef></p><p><termdef id="serialize-as-HTML" term="serialized as an HTML element" open="true">An element node is <term>serialized as an
HTML element</term> if</termdef></p><ulist><item><p>the expanded QName of the element has a
<termref def="null-namespace-URI">null namespace URI</termref>, or
</p></item><item><p>the <termref def="req-html-ver">requested HTML version</termref> is <code nobreak="false">5.0</code> or
greater, and the element node is in the
<termref def="xhtml-namespace">XHTML namespace</termref>.</p></item></ulist><p role="closetermdef"/><p>If the 
element is to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref>,
but the local part of the expanded QName is not recognized as the name
of an HTML element, the element 
<rfc2119>MUST</rfc2119> be output in the same way as a
non-empty, inline element such as <code nobreak="false">span</code>. In particular:</p><olist><item><p>
Any namespace node in the result tree
for the <termref def="xml-namespace">XML namespace</termref> is ignored
by the HTML output method.
In addition,
if the 
<termref def="req-html-ver">requested HTML version</termref>
is <code nobreak="false">5.0</code>, any element node that has a prefix and is in the
<termref def="xhtml-namespace">XHTML namespace</termref>,
<termref def="mathml-namespace">MathML namespace</termref>,
or <termref def="svg-namespace">SVG namespace</termref>
<rfc2119>MUST</rfc2119> be serialized
with an unprefixed element name.  The <termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119>
serialize an attribute with the name <code nobreak="false">xmlns</code> whose value is
equal to the namespace URI of the element node, unless an ancestor
element in the serialized result already has an attribute named
<code nobreak="false">xmlns</code> with the same value, and no intervening element 
has an attribute named <code nobreak="false">xmlns</code> with a different value.
If the element
node has a namespace node for the default namespace whose value is not
equal to the namespace URI of the element node,
the namespace node is ignored.
The <termref def="serializer">serializer</termref>
<rfc2119>MUST NOT</rfc2119> serialize a namespace declaration for the
namespace node declaring the element node’s prefix, unless an attribute
of the element node has the same prefix.


For namespace nodes in the result tree
that are not ignored, the HTML output method 
<rfc2119>MUST</rfc2119> represent these namespaces using
attributes named <code nobreak="false">xmlns</code> or <code nobreak="false">xmlns:</code><emph>prefix</emph>
in the same way as the XML output method would represent them when the
<code nobreak="false">version</code> parameter is set to <code nobreak="false">1.0</code>.</p></item><item><p>If the <termref def="result-tree">result tree</termref> contains elements or attributes whose names have a
<termref def="non-null-namespace-URI">non-null namespace URI</termref>, the HTML output method

<rfc2119>MUST</rfc2119> generate
namespace-prefixed QNames for these nodes in the same way as the XML output
method would do when the <code nobreak="false">version</code> parameter is set to <code nobreak="false">1.0</code>.</p></item><item><p>Where special rules are defined later in this section for
serializing specific HTML elements and attributes, these rules

<rfc2119>MUST NOT</rfc2119> be 
applied to an element that is not to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref>
or an attribute whose name has
a <termref def="non-null-namespace-URI">non-null
namespace URI</termref>. However, the generic rules for the HTML output method
that apply to all elements and attributes, for example the rules for
escaping special characters in the text and the rules for indentation,
<rfc2119>MUST</rfc2119> be used also for namespaced elements and attributes.</p></item><item><p>When serializing an element whose name is not defined in the
HTML specification, but that is
to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref>, the HTML output method

<rfc2119>MUST</rfc2119>
apply the same rules (for example, indentation rules) as
when serializing a <code nobreak="false">span</code> element. The descendants of such
an element 
<rfc2119>MUST</rfc2119> be serialized as if they were descendants of a
<code nobreak="false">span</code> element.</p></item><item><p>When serializing an element whose name is in a non-null
namespace, the HTML output method 
<rfc2119>MUST</rfc2119> apply the same rules (for
example, indentation rules) as when serializing a <code nobreak="false">div</code>
element. The descendants of such an element

<rfc2119>MUST</rfc2119> be serialized as if
they were descendants of a <code nobreak="false">div</code> element,<!--Text inserted by erratum E4 change 1"-->
        except for the influence
          of the <code nobreak="false">cdata-section-elements</code> serialization parameter
          on any text node children of the element.
      <!--End of text inserted by erratum E4--></p></item></olist><!--Text replaced by erratum E7 change 2"--><p>The HTML output method 
<rfc2119>MUST NOT</rfc2119> output an end-tag for an empty element
if the element type has an empty content model,
and the value of the
<termref def="req-html-ver">requested HTML
version</termref>
is less than <code nobreak="false">5.0</code>, or the element is a void
element and the value of the
<termref def="req-html-ver">requested HTML
version</termref>
is <code nobreak="false">5.0</code>. For example, an element written as
<code nobreak="false">&lt;br/&gt;</code> or <code nobreak="false">&lt;br&gt;&lt;/br&gt;</code> in an
XSLT stylesheet 
<rfc2119>MUST</rfc2119> be output as <code nobreak="false">&lt;br&gt;</code>.</p><p>For HTML 4.0, the
element types that have an empty content model are 
<code nobreak="false">area</code>, <code nobreak="false">base</code>, <code nobreak="false">basefont</code>,
<code nobreak="false">br</code>, <code nobreak="false">col</code>,
<code nobreak="false">embed</code>,
<code nobreak="false">frame</code>,
<code nobreak="false">hr</code>, <code nobreak="false">img</code>, <code nobreak="false">input</code>,
<code nobreak="false">isindex</code>, <code nobreak="false">link</code>, <code nobreak="false">meta</code> and
<code nobreak="false">param</code>.
For HTML5, the void elements are
<code nobreak="false">area</code>, <code nobreak="false">base</code>,
<code nobreak="false">br</code>, <code nobreak="false">col</code>, <code nobreak="false">embed</code>,
<code nobreak="false">hr</code>, <code nobreak="false">img</code>, <code nobreak="false">input</code>,
<code nobreak="false">keygen</code>, <code nobreak="false">link</code>, <code nobreak="false">meta</code>,
<code nobreak="false">param</code>, <code nobreak="false">source</code>, <code nobreak="false">track</code> and
<code nobreak="false">wbr</code>.  It is <termref def="impdef">implementation-defined</termref>
whether the <code nobreak="false">basefont</code>, <code nobreak="false">frame</code> and <code nobreak="false">isindex</code>
elements, which are not part of HTML5, are considered to be void elements when
the
<termref def="req-html-ver">requested HTML
version</termref>
has the value <code nobreak="false">5.0</code>.
</p><imp-def-feature>
For the HTML output method,
it is <termref def="impdef">implementation-defined</termref>
whether the <code nobreak="false">basefont</code>, <code nobreak="false">frame</code> and <code nobreak="false">isindex</code>
elements, which are not part of HTML5, are considered to be void elements when
the <termref def="req-html-ver">requested HTML
version</termref> has the value <code nobreak="false">5.0</code>.

</imp-def-feature><!--End of text replaced by erratum E7--><!--Start of text added for Bug 6723--><note><p>The markup generation step of the
<termref def="serphases">phases of serialization</termref> only creates
start tags and end tags for the HTML output method, never XML-style
empty element tags.  As such, a <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> serialize an HTML
element that has no children, but whose content model is not empty,
using a pair of adjacent start and end element tags, or as a solitary
start tag if permitted by the context.
</p></note><!--End of text added for Bug 6723--><p>For any element node that is to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref>,
the HTML output method 
<rfc2119>MUST</rfc2119>
compare the local part of the name of
the element node with the names of HTML elements,
<!-- Start of text changed for Bug 8651 (Erratum SE.E17) -->
making the comparison
<termref def="caseless-compare">without regard to case</termref>.
<!-- End of text changed for Bug 8651 (Erratum SE.E17) -->
If the local part of the name of the
element node compares equal to that of any HTML element, the element node
<rfc2119>MUST</rfc2119> be recognized as being that kind of HTML
element.
For example, elements named
<code nobreak="false">br</code>, <code nobreak="false">BR</code> or <code nobreak="false">Br</code> 
<rfc2119>MUST</rfc2119> all be
recognized as the HTML <code nobreak="false">br</code> element and output without an
end tag.</p><p>The HTML output method 
<rfc2119>MUST NOT</rfc2119> perform escaping for
<!-- Start of changes for Bug 7823 (erratum E16) -->
any text node
descendant, nor for any attribute of an element node descendant,
of
a
<code nobreak="false">script</code>
or
<code nobreak="false">style</code>
element.
<!-- End of changes for Bug 7823 (erratum E16) -->
</p><example><p>For example, a <code nobreak="false">script</code> element
created by an XQuery direct element constructor or an XSLT
literal result element, such as:</p><eg xml:space="preserve">&lt;script&gt;if (a &amp;lt; b) foo()&lt;/script&gt;</eg><p>or</p><eg xml:space="preserve">&lt;script&gt;&lt;![CDATA[if (a &lt; b) foo()]]&gt;&lt;/script&gt;</eg><p>
<rfc2119>MUST</rfc2119> be output as</p><eg xml:space="preserve">&lt;script&gt;if (a &lt; b) foo()&lt;/script&gt;</eg></example><example><p>A common requirement is to output a <code nobreak="false">script</code> element
as shown in the example below:</p><eg xml:space="preserve">&lt;script type="application/ecmascript"&gt;
      document.write ("&lt;em&gt;This won't work&lt;/em&gt;")
&lt;/script&gt;</eg><p>This is
invalid
HTML, for the reasons explained in section B.3.2 of
the <bibref ref="html401"/> 4.01 specification. Nevertheless, it is possible to output
this fragment using either of the following constructs:</p><p>Firstly, by use of a <code nobreak="false">script</code> element
created by an XQuery direct element constructor or an
XSLT literal result element:</p><eg xml:space="preserve">&lt;script type="application/ecmascript"&gt;
      document.write ("&lt;em&gt;This won't work&lt;/em&gt;")
&lt;/script&gt;</eg><p>Secondly, by constructing the markup from ordinary text characters:</p><eg xml:space="preserve">&lt;script type="application/ecmascript"&gt;
      document.write ("&amp;lt;em&amp;gt;This won't work&amp;lt;/em&amp;gt;")
&lt;/script&gt;</eg><p>As the <bibref ref="html401"/> specification points out, the correct way to write this
is to use the escape conventions for the specific scripting language.
For JavaScript, it can be written as:</p><eg xml:space="preserve">&lt;script type="application/ecmascript"&gt;
      document.write ("&amp;lt;em&amp;gt;This will work&amp;lt;\/em&amp;gt;")
&lt;/script&gt;</eg><p>The <bibref ref="html401"/> 4.01 specification also shows examples of how to write
this in various other scripting languages. The escaping <rfc2119>MUST</rfc2119> be done
explicitly; it will not be done by the <termref def="serializer">serializer</termref>.</p></example></div2><div2 id="HTML_ATTRIBS"><head>Writing Attributes</head><p>The HTML output method
<rfc2119>MUST NOT</rfc2119> escape
"<code nobreak="false">&lt;</code>" characters occurring in attribute values.</p><!-- Start of text changed under Bug 7829 (Erratum SE.E14) --><p>A boolean attribute is an
attribute with only a single allowed value in any of the HTML DTDs
or that is specified to be a boolean
attribute by HTML5 (see <bibref ref="html5"/>), where the
allowed value is equal without regard to case
to the name of the attribute. 
The HTML output method <rfc2119>MUST</rfc2119> output any boolean attribute in minimized form if
and only if the value of the attribute node actually is equal to the name of
the attribute
<!-- Start of text changed under Bug 8651 (Erratum SE.E17) -->

making the comparison <termref def="caseless-compare">without regard to case</termref>.
<!-- End of text changed under Bug 8651 (Erratum SE.E17) -->
</p><!-- End of text changed under Bug 7829 (Erratum SE.E14) --><example><p>For example, a start-tag created
using the following XQuery direct element constructor or XSLT
literal result element</p><eg xml:space="preserve">&lt;OPTION selected="selected"&gt;</eg><p><rfc2119>MUST</rfc2119> be output as</p><eg xml:space="preserve">&lt;OPTION selected&gt;</eg></example><p>The HTML output method 
<rfc2119>MUST NOT</rfc2119> escape a
<code nobreak="false">&amp;</code> character occurring in an attribute value
immediately followed by a <code nobreak="false">{</code> character (see <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.7.1.1" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Section
B.7.1</loc> of the HTML Recommendation <bibref ref="html401"/>).</p><example><p>For example, a start-tag created
using the following XQuery direct element constructor or XSLT
literal result element</p><eg xml:space="preserve">&lt;BODY bgcolor='&amp;amp;{{randomrbg}};'&gt;</eg><p>
<rfc2119>MUST</rfc2119> be output as</p><eg xml:space="preserve">&lt;BODY bgcolor='&amp;{randomrbg};'&gt;</eg></example><p>See <specref ref="HTML_PARAMS"/> for additional directives on how attributes <rfc2119>MAY</rfc2119> be written.</p></div2><div2 id="HTML_CHARDATA"><head>Writing Character Data</head><p>The HTML output method <rfc2119>MAY</rfc2119> output a character using a
    character entity reference in preference to using a numeric character
    reference, if an entity is defined for the character in the version of
    HTML that the output method is using. Entity references and character
    references <rfc2119>SHOULD</rfc2119> be used only where the character is not present in
    the selected encoding, or where the visual representation of the
    character is unclear (as with <code nobreak="false">&amp;nbsp;</code>, for
    example).</p><p>When outputting a sequence of
    <termref def="whitespace-char">whitespace characters</termref> in the
      <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>, within an element where
    whitespace characters are treated normally
    (but not in elements such as <code nobreak="false">pre</code> and
    <code nobreak="false">textarea</code>), the HTML output method
    <rfc2119>MAY</rfc2119> represent it using any sequence of whitespace
    characters that will be treated
    in the same way by an HTML user agent. See section 3.5 of <bibref ref="xhtml-modularization"/> for some additional information on
    handling of whitespace by an HTML user agent
    for versions of HTML prior to HTML5,
    and see <bibref ref="html5"/> for information on the handling of whitespace
    characters by an HTML5 user agent.
    </p><note><p>The terms space character
    and whitespace character defined in HTML5 do not match the definition of
    <termref def="whitespace-char">whitespace character</termref> in this
    specification.</p></note><p>Certain characters are permitted in XML, but not in HTML prior to HTML5
    — for example,
    the control characters <char>U+007F</char> through <char>U+009F</char> are
    permitted in both XML 1.0 and XML 1.1, and
    the control characters <char>U+0001</char> through <char>U+0008</char>,
      <char>U+000B</char>, <char>U+000C</char> and <char>U+000E</char> through <char>U+001F</char> are
    permitted in XML 1.1, but none of these is permitted in HTML prior to HTML5.
    
    It is a <termref def="serial-err">serialization error</termref> <errorref code="0014" class="RE"/> to use the HTML
    output method if such characters
    appear in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>
    and the value of the <termref def="req-html-ver">requested HTML
    version</termref> is less than <code nobreak="false">5.0</code>. The
    <termref def="serializer">serializer</termref>
    <rfc2119>MUST</rfc2119> raise the error.</p></div2><div2 id="HTML_COMMENTS_AND_PIS"><head>Writing Comments and Processing Instructions</head><changes><change issue="2344" PR="2372" date="2026-01-20">The way processing instructions are handled when generating HTML5 has changed, reflecting the fact
      that HTML5 no longer recognizes processing instructions.</change></changes><p>Comment nodes are written as HTML comments, using the syntax <code nobreak="false">&lt;!--comment--&gt;</code>.</p><p><termref def="id-prior-to-html5">Prior to HTML5</termref>,    
      the HTML output method 
      <rfc2119>MUST</rfc2119> terminate processing
      instructions with <code nobreak="false">&gt;</code> rather than
      <code nobreak="false">?&gt;</code>.  It is a <termref def="serial-err">serialization error</termref> <errorref code="0015" class="RE"/> 
      to use the HTML output method when <code nobreak="false">&gt;</code> 
        appears within a processing instruction in <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>.</p><p><termref def="id-with-html5">With HTML5</termref>, a processing instruction <rfc2119>MUST</rfc2119> be written as an HTML comment,
    in the form <code nobreak="false">&lt;!--?<var>target</var> <var>data</var>?--&gt;</code>. Here <var>target</var> is the name of the 
    processing instruction, and <var>data</var> is its string value; they are separated by a single space. If the string
    value of the processing instruction contains two adjacent hyphens, they <rfc2119>MUST</rfc2119> 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 <code nobreak="false">&lt;?xml-stylesheet type="text/xsl" href="render.xsl"?&gt;</code>
    is serialized as <code nobreak="false">&lt;--?xml-stylesheet type="text/xsl" href="render.xsl"?--&gt;</code></p></div2><div2 id="HTML_PARAMS"><head>The Influence of Serialization Parameters upon the HTML Output Method</head><p>The serialization parameters that affect the HTML output method are listed
    in the following subsections.</p><p>Serialization parameters other than those listed are not applicable to this output
    method.  It is the responsibility of the
    <termref def="host-language">host language</termref> to specify
    whether an error occurs if such a parameter is specified in combination
    with the HTML output method, or whether the parameter is ignored, or whether
    it is validated and then ignored.</p><div3 id="HTML_VERSION"><head>HTML Output Method: the <code nobreak="false">version</code>
and <code nobreak="false">html-version</code>
Parameters</head><p>These two parameters are used to determine the <termref def="req-html-ver"/>.</p><!--<p>The
<code>html-version</code> or the
<code>version</code> 
serialization parameter
indicates the version of the HTML
Recommendation <bibref ref="html401"/>
or <bibref ref="html5"/>
to which the serialized result is
to conform.
<termdef id="req-html-ver" term="requested HTML version">
If the
<code>html-version</code> serialization parameter is not absent, the
<term>requested HTML version</term> is the value of the
<code>html-version</code> serialization parameter; otherwise, it is
the value of the <code>version</code> serialization
parameter.</termdef>
If the <termref def="serializer">serializer</termref> does
not support the version of HTML specified by
the <termref def="req-html-ver">requested
HTML version</termref>, it
<rfc2119>MUST</rfc2119> raise a
<termref def="serial-err">serialization error</termref> <errorref code="0013" class="SU"/>.</p>
<!-\- Start:  added for Bug 6732 -\->
<p>This document provides the normative
definition of serialization for the HTML output method if the
<termref def="req-html-ver">requested HTML version</termref>
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 value of
version parameter, the behavior is
<termref def="impdef">implementation-defined</termref>.
In that case the
<termref def="impdef">implementation-defined</termref>
behavior <rfc2119>MAY</rfc2119> supersede all other requirements
of this recommendation.</p>
<imp-def-feature>If an implementation
supports a value of the <code>version</code> parameter for the HTML output
method for which this document does not provide a normative definition, the
behavior is <termref def="impdef">implementation-defined</termref>.</imp-def-feature>
<!-\- End:  added for Bug 6732 -\->--></div3><div3 id="HTML_ENCODING"><head>HTML Output Method: the <code nobreak="false">encoding</code> Parameter</head><p>The <code nobreak="false">encoding</code> parameter specifies the encoding to be used.
<termref def="serializer">Serializers</termref> are
<rfc2119>REQUIRED</rfc2119>  to support values of <code nobreak="false">UTF-8</code> and
<code nobreak="false">UTF-16</code>. A <termref def="serial-err">serialization error</termref> <errorref code="0007" class="SU"/> occurs if an output
encoding other than <code nobreak="false">UTF-8</code> or <code nobreak="false">UTF-16</code> is
requested and the <termref def="serializer">serializer</termref>
does not support that encoding. The <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error.
</p><p>It is possible that the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> will contain a character that
cannot be represented in the encoding that the <termref def="serializer">serializer</termref>
is using for
output. In this case, if the character occurs in a context where HTML
recognizes character references, then the character 
<rfc2119>MUST</rfc2119> be output
as a character entity reference or decimal numeric character
reference; otherwise (for example, in a <code nobreak="false">script</code> or
<code nobreak="false">style</code> element or in a comment), the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119>
raise a <termref def="serial-err">serialization error</termref> <errorref code="0008" class="RE"/>.
</p><p>See <specref ref="HTML_INCLUDE-CONTENT-TYPE"/> regarding how this parameter is used with the <code nobreak="false">include-content-type</code> parameter.</p></div3><div3 id="HTML_INDENT"><head>HTML Output Method: the <code nobreak="false">indent</code> and <code nobreak="false">suppress-indentation</code> Parameters</head><!--Text replaced by erratum E9 change 3"--><p>If the <code nobreak="false">indent</code> parameter has 
the value <code nobreak="false">true</code>,
then the
HTML output method <rfc2119>MAY</rfc2119> add or remove whitespace as it
serializes the <termref def="result-tree">result tree</termref>,
if it observes the following
constraints.</p><ulist><item><p>Whitespace <rfc2119>MUST NOT</rfc2119> be added other than before or
after an element, or adjacent to an existing whitespace character.</p></item><item><p>Whitespace <rfc2119>MUST NOT</rfc2119> be added or removed adjacent to
an inline element.  The inline elements are:</p><ulist><item><p><termref def="id-prior-to-html5">Prior to HTML5</termref>: elements included in the
<code nobreak="false">%inline</code> category of any of the HTML 4.01 DTDs</p></item><item><p><termref def="id-with-html5">With HTML5</termref>: elements defined to be phrasing
elements in HTML5</p></item></ulist><p>as well as the <code nobreak="false">ins</code> and <code nobreak="false">del</code> elements if they do 
    not contain element children.</p></item><item><p>Whitespace <rfc2119>MUST NOT</rfc2119> be added or removed inside a
formatted element, the formatted elements being <code nobreak="false">pre</code>,
<code nobreak="false">script</code>, <code nobreak="false">style</code>,
<code nobreak="false">title</code>,
and <code nobreak="false">textarea</code>.
</p></item><!--End of text replaced by erratum E9--><item><p>Whitespace characters
<rfc2119>MUST NOT</rfc2119> be added in the content of an element
whose expanded QName matches
a member of the list of expanded QNames in the
value of the <code nobreak="false">suppress-indentation</code> parameter.
The expanded QName of an element node
is considered to match a member of the list of expanded QNames
if:</p><ulist><item><p>the two expanded QNames are equal;</p></item><item><p>the expanded QNames both have <termref def="null-namespace-URI">null
namespace URIs</termref>, and the local parts of the two QNames are
equal <termref def="caseless-compare">without regard to case</termref>; or
</p></item><item><p>the value of the
<termref def="req-html-ver">requested HTML
version</termref>
is <code nobreak="false">5.0</code>, the local parts of the two QNames are equal
<termref def="caseless-compare">without regard to case</termref>
and one QName has a <termref def="null-namespace-URI">null namespace
URI</termref> and the namespace URI of the other is equal to the XHTML
namespace URI.</p></item></ulist></item></ulist><note><!--Text replaced by erratum E9 change 4"--><p>The effect of the above constraints is to
ensure that any insertion or deletion of whitespace would not affect how a
conforming
HTML user agent would render the output, assuming the serialized document does
not refer to any HTML style sheets.</p><!--End of text replaced by erratum E9--><p>Note that the HTML definition of whitespace is different from the XML definition
(see section 9.1 of the <bibref ref="html401"/> specification).</p></note></div3><div3 id="HTML_CDATA-SECTION-ELEMENTS"><head>HTML Output Method: the <code nobreak="false">cdata-section-elements</code> Parameter</head><p>The <code nobreak="false">cdata-section-elements</code> parameter is not applicable to the HTML output method, except in the case of <termref def="XML-ISLAND">XML Islands</termref>.</p></div3><div3 id="HTML_DOCTYPE"><head>HTML Output Method: the <code nobreak="false">doctype-system</code> and <code nobreak="false">doctype-public</code> Parameters</head><p>If the <code nobreak="false">doctype-public</code> or <code nobreak="false">doctype-system</code>
parameters are specified, then the HTML output method <rfc2119>MUST</rfc2119>
output a document type declaration.
If the
<code nobreak="false">doctype-public</code> parameter is specified, then the output
method 
<rfc2119>MUST</rfc2119> output <code nobreak="false">PUBLIC</code>
followed by the specified
public identifier; if the <code nobreak="false">doctype-system</code> parameter is
also specified, it 
<rfc2119>MUST</rfc2119> also output the specified
system identifier
following the public identifier. If the <code nobreak="false">doctype-system</code>
parameter is specified but the <code nobreak="false">doctype-public</code> parameter
is not specified, then the output method
<rfc2119>MUST</rfc2119> output
<code nobreak="false">SYSTEM</code> followed by the specified system identifier.</p><p>If the value of the
<termref def="req-html-ver">requested HTML
version</termref>
is <code nobreak="false">5.0</code>, the
<code nobreak="false">doctype-public</code> and <code nobreak="false">doctype-system</code> serialization
parameters are both absent,
the first element node child of
the document node that is to be serialized
is to be
<termref def="serialize-as-HTML">serialized as an HTML
element</termref>, the local part of the QName of which is equal to
the string <code nobreak="false">HTML</code>,
<termref def="caseless-compare">without regard to case</termref>,
and any text node that precedes that
element node in the document contains only whitespace characters,
then
the HTML output method <rfc2119>MUST</rfc2119> output a document type
declaration, with no public or system identifier.</p><p>If the HTML output method <rfc2119>MUST</rfc2119>
output a document type declaration, it <rfc2119>MUST</rfc2119> be serialized
immediately before the first element, if any, and the name following
<code nobreak="false">&lt;!DOCTYPE</code> <rfc2119>MUST</rfc2119> be <code nobreak="false">HTML</code>
or <code nobreak="false">html</code>.</p></div3><div3 id="HTML_NORMALIZATION-FORM"><head>HTML Output Method: the <code nobreak="false">normalization-form</code> Parameter</head><p>The
<code nobreak="false">normalization-form</code>
parameter is applicable to the
HTML output method.
The values <code nobreak="false">NFC</code> and
<code nobreak="false">none</code> <rfc2119>MUST</rfc2119> be supported by the <termref def="serializer">serializer</termref>.
A <termref def="serial-err">serialization error</termref> <errorref code="0011" class="SU"/> results if the value of the <code nobreak="false">normalization-form</code>
parameter specifies a normalization form that is not supported by the
<termref def="serializer">serializer</termref>;
the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error.</p></div3><div3 id="HTML_MEDIA-TYPE"><head>HTML Output Method: the <code nobreak="false">media-type</code> Parameter</head><p>The <code nobreak="false">media-type</code> parameter is applicable to the
HTML output method.
See <specref ref="serparam"/> for more
information.  See <specref ref="HTML_INCLUDE-CONTENT-TYPE"/> regarding how this parameter is used with the <code nobreak="false">include-content-type</code> parameter.</p></div3><div3 id="HTML_USE-CHARACTER-MAPS"><head>HTML Output Method: the <code nobreak="false">use-character-maps</code> Parameter</head><p>The <code nobreak="false">use-character-maps</code> parameter is applicable to the
HTML output method.  See <specref ref="character-maps"/> for more
information.</p></div3><div3 id="HTML_BYTE-ORDER-MARK"><head>HTML Output Method: the <code nobreak="false">byte-order-mark</code> Parameter</head><p>The <code nobreak="false">byte-order-mark</code> parameter is
applicable to the HTML output method.  See
<specref ref="serparam"/> for more information.</p></div3><div3 id="HTML_ESCAPE-URI-ATTRIBUTES"><head>HTML Output Method: the <code nobreak="false">escape-uri-attributes</code> Parameter</head><p>
If the <code nobreak="false">escape-uri-attributes</code> parameter
has the value <code nobreak="false">true</code>,
the HTML output method <rfc2119>MUST</rfc2119>
apply <termref def="uri-escaping">URI escaping</termref> to 
<termref def="uri-attribute-values">URI attribute values</termref>, except that relative URIs <rfc2119>MUST NOT</rfc2119> be absolutized.
</p><note><p>This escaping is deliberately confined to non-ASCII characters,
because escaping of ASCII characters is not always appropriate, for
example when URIs or URI fragments are interpreted locally by the HTML
user agent. Even in the case of non-ASCII characters, escaping can
sometimes cause problems. More precise control of <termref def="uri-escaping">URI escaping</termref> is
therefore available by setting <code nobreak="false">escape-uri-attributes</code> to
<code nobreak="false">false</code>, and controlling the escaping of URIs by using methods defined in
<xspecref spec="FO40" ref="func-encode-for-uri"/> and <xspecref spec="FO40" ref="func-iri-to-uri"/>.</p></note></div3><div3 id="HTML_INCLUDE-CONTENT-TYPE"><head>HTML Output Method: the <code nobreak="false">include-content-type</code> Parameter</head><p>If there is a <code nobreak="false">head</code> element,
and the <code nobreak="false">include-content-type</code> parameter has 
the value <code nobreak="false">true</code>,
the HTML output method
<rfc2119>MUST</rfc2119> add a <code nobreak="false">meta</code> element
as the first child element
of the <code nobreak="false">head</code> element specifying the character encoding
  actually used.</p><p><termref def="id-prior-to-html5">Prior to HTML5</termref>, the generated <code nobreak="false">meta</code>
  element <rfc2119>MUST</rfc2119> take the form shown below (assuming encoding <code nobreak="false">EUC-JP</code>):</p><eg xml:space="preserve">&lt;head&gt;
&lt;meta http-equiv="Content-Type" 
      content="text/html; charset=EUC-JP" &gt;
...</eg><p><termref def="id-with-html5">With HTML5</termref>, the generated <code nobreak="false">meta</code>
  element <rfc2119>MUST</rfc2119> take the form shown below (again assuming encoding <code nobreak="false">EUC-JP</code>):</p><eg xml:space="preserve">&lt;head&gt;
&lt;meta charset="EUC-JP"&gt;
...</eg><p>The content type<phrase diff="add" at="2023-02-09">, when included,</phrase> <rfc2119>MUST</rfc2119>
be set to the value given for the
<code nobreak="false">media-type</code> parameter.</p><!--Text replaced by erratum E5 change 1"--><p>If a <code nobreak="false">meta</code> element has been added to the <code nobreak="false">head</code> element as described above,
then any existing <code nobreak="false">meta</code> element child of the <code nobreak="false">head</code> element having 
  <phrase diff="add" at="2023-02-09">a <code nobreak="false">charset</code> attribute or</phrase>
  an <code nobreak="false">http-equiv</code> attribute with the value
"Content-Type", making the comparison
<!-- Start of text changed under bug 8651 (Erratum SE.E17) -->
<termref def="caseless-compare">without regard to case</termref>
after first stripping leading and trailing spaces from the value of
the attribute solely for the purposes of comparison,
<!-- End of text changed under bug 8651 (Erratum SE.E17) -->
<rfc2119>MUST</rfc2119> be discarded.</p><!--End of text replaced by erratum E5--><note><p>This process removes possible parameters in the
attribute value.  For example,</p><eg xml:space="preserve">&lt;meta http-equiv="Content-Type" 
      content="text/html;version='4.0'"&gt;</eg><p>in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
    <phrase diff="add" at="2023-02-09">might</phrase> be replaced by</p><eg xml:space="preserve">&lt;meta http-equiv="Content-Type" 
      content="text/html;charset=UTF-8"&gt;</eg><p diff="add" at="2023-02-09">or by</p><eg xml:space="preserve">&lt;meta charset="UTF-8"&gt;</eg></note></div3><div3 id="HTML_ITEM-SEPARATOR"><head>HTML Output Method: the <code nobreak="false">item-separator</code> Parameter</head><p>The effect of the <code nobreak="false">item-separator</code> serialization parameter
is described in <specref ref="serdm"/>.</p></div3></div2></div1><div1 id="text-output"><head>Text Output Method</head><!--Text replaced by erratum E8 change 2"--><p>The Text output method serializes the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> by
outputting the <termref def="dt-string-value">string value</termref> of the
document node created by
the markup generation step of the
<termref def="serphases">phases of serialization</termref> without any
escaping.</p><!--End of text replaced by erratum E8--><p>A newline character in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
    <rfc2119>MAY</rfc2119> be output using any
character sequence that is conventionally used to represent a line
ending in the chosen system environment.</p><note><p>The rule just stated applies to the character <char>U+000A</char>; it does
  not apply to occurrences in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> of 
  <char>U+000D</char>, <code nobreak="false">U+0085</code>, or <code nobreak="false">U+2028</code>: these should be output
literally, regardless of the conventions for line endings in the
system environment.</p><p>To illustrate, the following table shows the expected output
for various character sequences in environments which conventionally
use <char>U+000A</char> (LF, as in Linux systems), <char>U+000D</char> followed by <char>U+000A</char> (CR+LF, Windows), 
  <char>U+000D</char> (CR only, older versions of Mac OS),
  <code nobreak="false">U+0085</code> (some IBM operating systems),
  or <code nobreak="false">U+2028</code> to separate lines:</p><table role="medium no-code-break" border="1" summary="Expected output for various character sequences"><thead><tr><th align="left" rowspan="1" colspan="1">Input</th><th align="left" rowspan="1" colspan="1">#xA systems</th><th align="left" rowspan="1" colspan="1">#xD#xA systems</th><th align="left" rowspan="1" colspan="1">#xD systems</th><th align="left" rowspan="1" colspan="1">#x85 systems</th><th align="left" rowspan="1" colspan="1">#x2028 systems</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">character #xD</td><td rowspan="1" colspan="1">character #xD</td><td rowspan="1" colspan="1">character #xD</td><td rowspan="1" colspan="1">character #xD</td><td rowspan="1" colspan="1">character #xD</td><td rowspan="1" colspan="1">character #xD</td></tr><tr><td rowspan="1" colspan="1">character #xA</td><td rowspan="1" colspan="1">character #xA</td><td rowspan="1" colspan="1">string #xD + #xA</td><td rowspan="1" colspan="1">character #xD</td><td rowspan="1" colspan="1">character #x85</td><td rowspan="1" colspan="1">character #x2028</td></tr><tr><td rowspan="1" colspan="1">string #xD + #xA</td><td rowspan="1" colspan="1">string #xD + #xA</td><td rowspan="1" colspan="1">string #xD + #xD + #xA</td><td rowspan="1" colspan="1">string #xD + #xD</td><td rowspan="1" colspan="1">string #xD + #x85</td><td rowspan="1" colspan="1">string #xD + #x2028</td></tr><tr><td rowspan="1" colspan="1">string #xD + #xD + #xA</td><td rowspan="1" colspan="1">string #xD + #xD + #xA</td><td rowspan="1" colspan="1">string #xD + #xD + #xD + #xA</td><td rowspan="1" colspan="1">string #xD + #xD + #xD</td><td rowspan="1" colspan="1">string #xD + #xD + #x85</td><td rowspan="1" colspan="1">string #xD + #xD + #x2028</td></tr></tbody></table></note><div2 id="TEXT_PARAMS"><head>The Influence of Serialization Parameters upon the Text Output Method</head><p>The serialization parameters that affect the Text output method are listed
    in the following subsections.</p><p>Serialization parameters other than those listed are not applicable to this output
    method.  It is the responsibility of the
    <termref def="host-language">host language</termref> to specify
    whether an error occurs if such a parameter is specified in combination
    with the Text output method, or whether the parameter is ignored, or whether
    it is validated and then ignored.</p><div3 id="TEXT_ENCODING"><head>Text Output Method: the <code nobreak="false">encoding</code> Parameter</head><p>The <code nobreak="false">encoding</code> parameter identifies the encoding that
the Text output method
<rfc2119>MUST</rfc2119> use to convert sequences of
characters to sequences of bytes.
<termref def="serializer">Serializers</termref>
are <rfc2119>REQUIRED</rfc2119> to support values of <code nobreak="false">UTF-8</code> and
<code nobreak="false">UTF-16</code>.
A <termref def="serial-err">serialization error</termref> <errorref code="0007" class="SU"/>
occurs if the <termref def="serializer">serializer</termref>
does not support the encoding specified
by the <code nobreak="false">encoding</code> parameter.
The <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error.
  If the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> contains a
character that cannot be represented in the encoding that the
<termref def="serializer">serializer</termref> is using for output, the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119>
raise a <termref def="serial-err">serialization error</termref> <errorref code="0008" class="RE"/>.</p></div3><div3 id="TEXT_NORMALIZATION-FORM"><head>Text Output Method: the <code nobreak="false">normalization-form</code> Parameter</head><p>The <code nobreak="false">normalization-form</code>
parameter is applicable to the
Text output method.
The values <code nobreak="false">NFC</code>
and <code nobreak="false">none</code> <rfc2119>MUST</rfc2119> be supported by the <termref def="serializer">serializer</termref>.
A <termref def="serial-err">serialization error</termref> <errorref code="0011" class="SU"/> results if the value of the
<code nobreak="false">normalization-form</code> parameter specifies a normalization form
that is not supported by the <termref def="serializer">serializer</termref>; the
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the
error.</p></div3><div3 id="TEXT_MEDIA-TYPE"><head>Text Output Method: the <code nobreak="false">media-type</code> Parameter</head><p>The <code nobreak="false">media-type</code> parameter is applicable to the
Text output method.
See <specref ref="serparam"/> for more
information.</p></div3><div3 id="TEXT_USE-CHARACTER-MAPS"><head>Text Output Method: the <code nobreak="false">use-character-maps</code> Parameter</head><p>The <code nobreak="false">use-character-maps</code> parameter is applicable to the
Text output method.
See <specref ref="character-maps"/> for more
information.</p></div3><div3 id="TEXT_BYTE-ORDER-MARK"><head>Text Output Method: the <code nobreak="false">byte-order-mark</code> Parameter</head><p>The <code nobreak="false">byte-order-mark</code> parameter is
applicable to the Text output method.  See
<specref ref="serparam"/> for more information.</p></div3><div3 id="TEXT_ITEM-SEPARATOR"><head>Text Output Method: the <code nobreak="false">item-separator</code> Parameter</head><p>The effect of the <code nobreak="false">item-separator</code> serialization parameter
is described in <specref ref="serdm"/>.</p></div3></div2></div1><div1 id="json-output"><head>JSON Output Method</head><changes><change issue="530" PR="534" date="2023-06-06">
      Added the <code nobreak="false">escape-solidus</code> parameter for JSON serialization.
    </change><change issue="1471" date="2024-10-15">
      Added the <code nobreak="false">json-lines</code> parameter for JSON serialization.
    </change><change issue="1651" PR="1703" date="2025-01-14">
      The serialization of maps retains the order of entries.
    </change><change issue="2025" PR="2031" date="2025-05-29">
      A JNode is replaced by its <code nobreak="false">·content·</code> property.
    </change><change issue="938" PR="TODO" date="2025-10-20">
      JSON canonicalization is supported by the <code nobreak="false">·canonical·</code> property.
    </change><change issue="641" PR="2387" date="2026-01-16">
      The JSON output method now produces fallback representation of NaN and infinity, rather
      than reporting an error for such values.
    </change></changes><p>The JSON output method serializes the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>
    using the JSON syntax defined in <bibref ref="rfc7159"/>,
    or (if the <code nobreak="false">json-lines</code> parameter is set to true) the <term>json-lines</term>
    syntax defined at <bibref ref="JSON-LINES"/>.
    Sequence normalization is not performed for this output method.
    The effect of the <code nobreak="false">json-lines</code> parameter is explained at
    <specref ref="id-json-lines"/>.</p><p>If <code nobreak="false">json-lines</code> is set to <code nobreak="false">false</code>, then:</p><ulist><item><p>If the <termref def="dt-input-value"/> is an empty sequence, 
    it is serialized as the string <code nobreak="false">null</code>.</p></item><item><p>If the input value is a single item, it is serialized as
    described below.</p></item><item><p>If the input value is a sequence containing two or more items,
    a serialization error results <errorref code="0023" class="RE"/>.
    </p></item></ulist><div2 id="serializing-json-items"><head>Serializing Items</head><p>An individual item is serialized as follows:</p><ulist><item><p>A JNode is serialized by serializing its <code nobreak="false">·content·</code> property.</p></item><item><p>An <termref def="dt-array-item">array item</termref> in the
      <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> is
    serialized to a JSON array by outputting the serialized JSON value of
    each member
     within the array separated by delimiters according to the
    JSON array syntax, i.e. <code nobreak="false">[member, member, ...]</code>. Each member
    in the array is to be serialized by recursively applying the rules
    in this section.
    </p></item><item><p>A <termref def="dt-map-item">map item</termref> 
      in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>
    is serialized to a JSON object by outputting, for each key/value pair,
    the <termref def="dt-string-value">string value</termref> of the key 
    <termref def="to-a-json-string">to a JSON string</termref>, followed by
    the serialized JSON value of the entry,
    separated by delimiters according to the JSON object 
    syntax, i.e. <code nobreak="false">{key:value, key:value, ...}</code>.
    The key/value pairs in the serialized output retain the 
      <xtermref spec="DM40" ref="dt-entry-order">entry order</xtermref> of entries in the map,
    unless <code nobreak="false">canonical</code> is <code nobreak="false">true</code>, in
      which case map entries <rfc2119>MUST</rfc2119> be sorted according to the rules of <bibref ref="RFC8785"/>. 
    </p><note><p>These rules require sorting according to the UTF-16 representation of the string,
      which is not the same (in the presence of surrogate pairs) as sorting using the XPath codepoint
      collation.</p></note><p>If any two keys of the map item have the same 
    <termref def="dt-string-value">string value</termref>,
    serialization error <errorref code="0022" class="RE"/> is raised,
    unless the <code nobreak="false">allow-duplicate-names</code> parameter is <code nobreak="false">true</code> 
      and the <code nobreak="false">canonical</code> parameter is <code nobreak="false">false</code>.
    </p></item><item><p>
      A node in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>
    is serialized <termref def="to-a-json-string">to a JSON string</termref> by outputting 
    the result of serializing the node using the method specified by the 
    <code nobreak="false">json-node-output-method</code> parameter.  
    If the value of the <code nobreak="false">canonical</code> parameter is <code nobreak="false">false</code>, 
    the node is serialized with the serialization parameter <code nobreak="false">omit-xml-declaration</code> set
     to <code nobreak="false">true</code> and with no other serialization parameters set, otherwise (<code nobreak="false">canonical</code>
     is <code nobreak="false">true</code>) all parameters are inherited by the sub-serialization process.
    
    </p></item><item><p>An <xtermref spec="XP40" ref="dt-atomic-item">atomic
      value</xtermref> of type <code nobreak="false">xs:numeric</code> is
    serialized to a JSON number.</p><p>If the <code nobreak="false">canonical</code> parameter is <code nobreak="false">true</code>, then the value is cast to type <code nobreak="false">xs:double</code>
      and the result is serialized according to the rules of <bibref ref="RFC8785"/> (and by extension 
      <bibref ref="RFC7493"/>).</p><p>If the <code nobreak="false">canonical</code> parameter is <code nobreak="false">false</code> then:</p><ulist><item><p>A value of type <code nobreak="false">xs:decimal</code> (including <code nobreak="false">xs:integer</code>) is output
        in the format that results from casting the value to <code nobreak="false">xs:string</code>.</p></item><item><p>A value of type <code nobreak="false">xs:float</code> is first cast to type <code nobreak="false">xs:double</code>, and
        then output in the same way as an <code nobreak="false">xs:double</code>.</p></item><item><p>Implementations <rfc2119>MAY</rfc2119> serialize an
          <code nobreak="false">xs:double</code> value using any lexical representation of a JSON number defined in <bibref ref="rfc7159"/>,
           but it is <rfc2119>RECOMMENDED</rfc2119> to use the same representation as when
        the <code nobreak="false">canonical</code> parameter is <code nobreak="false">true</code>.</p></item><item><p>The value <code nobreak="false">NaN</code> is serialized as the JSON token <code nobreak="false">null</code>.</p></item><item><p>The values positive and negative infinity are serialized as <code nobreak="false">1e9999</code> and <code nobreak="false">-1e9999</code>
        respectively.</p><note><p>These values are permitted by the JSON grammar, but some JSON parsers may reject them. For
        interoperability, they should be avoided.</p></note></item></ulist><!--If the value of the serialization parameter <code>canonical</code> is <code>true</code>, literals, strings,
    and numbers <rfc2119>MUST</rfc2119> conform to the rules of <bibref ref="RFC8785"/> (and by extension 
    <bibref ref="RFC7493"/>); if they are not, then the <termref def="serializer">serializer</termref> 
    <rfc2119>MUST</rfc2119> raise serialization error <errorref code="0024" class="RE"/>. --></item><item><p>An <xtermref spec="XP40" ref="dt-atomic-item">atomic item</xtermref> 
      of type <code nobreak="false">xs:boolean</code>
     is serialized to the JSON token <code nobreak="false">true</code> or <code nobreak="false">false</code>.</p></item><item diff="add" at="2024-02-19"><p>An <xtermref spec="XP40" ref="dt-atomic-item">atomic item</xtermref> 
          of type <code nobreak="false">xs:QName</code> in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>
         whose namespace part is <code nobreak="false">"http://www.w3.org/2005/xpath-functions"</code> 
        and whose local part is <code nobreak="false">"null"</code> is
        serialized to the JSON token <code nobreak="false">null</code>.</p><note><p>This rule is introduced in 4.0, along with an option in the <code nobreak="false">fn:parse-json</code>
      function to allow a user-defined representation of the JSON value <code nobreak="false">null</code>. While
      the default representation of <code nobreak="false">null</code> as an empty sequence is usable in many
      circumstances, an explicit representation of <code nobreak="false">null</code> as a recognizable item can make
      some operations on JSON-derived values easier.</p></note></item><item><p>Any other <xtermref spec="XP40" ref="dt-atomic-item">atomic
      value</xtermref> in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
    is serialized <termref def="to-a-json-string">to a JSON string</termref> by outputting the 
    result of applying the <code nobreak="false">fn:string</code> function to the item.</p></item><item><p>An empty sequence in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
        is serialized to the JSON token <code nobreak="false">null</code>.</p></item><item><p>A sequence of length greater than 
      one in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
    will result in a serialization error <!--* [err:SERE0023] *-->
    <errorref code="0023" class="RE"/>.
    </p></item><item><p>
      Any item in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> of a type not specified in the above 
    list will result in a serialization error <!--* [err:SERE0021] *-->
    <errorref code="0021" class="RE"/>.</p></item></ulist><p>
    <termdef id="to-a-json-string" term="to a JSON string">Whenever a value is serialized
    <term>to a JSON string</term>, the following procedure is applied to the supplied string:</termdef></p><olist><item><p>If the <code nobreak="false">canonical</code> parameter is <code nobreak="false">true</code>, then the string is output
      as specified in <bibref ref="RFC8785"/>. The string is first normalized if requested using the
          <code nobreak="false">normalization-form</code> parameter. The serialization parameters 
      <code nobreak="false">escape-solidus</code> and <code nobreak="false">use-character-maps</code> are ignored.</p><note><p>The escaping rules are restated here for convenience:</p><ulist><item><p>If the Unicode value falls within the traditional ASCII control character range (<char>U+0000</char> through <char>U+001F</char>), 
          it <rfc2119>MUST</rfc2119> be serialized using lowercase hexadecimal Unicode notation (<code nobreak="false">\uhhhh</code>) unless it is in the set 
          of predefined JSON control characters <char>U+0008</char>, <char>U+0009</char>, <char>U+000A</char>, <char>U+000C</char>, 
              or <char>U+000D</char>, which <rfc2119>MUST</rfc2119> 
          be serialized as <code nobreak="false">\b</code>, <code nobreak="false">\t</code>, <code nobreak="false">\n</code>, <code nobreak="false">\f</code>, and <code nobreak="false">\r</code>, respectively.</p></item><item><p>If the Unicode value is outside of the ASCII control character range, 
              it <rfc2119>MUST</rfc2119> be serialized “as is” unless it is equivalent to <char>U+005C</char> or <char>U+0022</char>, 
              which <rfc2119>MUST</rfc2119> be serialized as <code nobreak="false">\\</code> and <code nobreak="false">\"</code>, respectively.</p></item></ulist><p>Note that the C1 control characters (codepoints 127-159) are not included in this list.</p></note><note><p>In canonical JSON, property values within an object are sorted based on their UTF16 representation.
        This corresponds to the default sort order in languages such as Javascript, Java, and C#, but in the presence
        of codepoints above 65535, it is not the same as the order produced by Unicode codepoint collation.</p></note></item><item><p>Otherwise (when <code nobreak="false">canonical</code> is <code nobreak="false">false</code>):</p><olist><item><p>Any character in the string for which character mapping is defined 
        (see <specref ref="character-maps"/>) is substituted by the replacement string defined in the character map.</p></item><item><p>
        Any other character in the input string (but not a character produced by character mapping) 
        is a candidate for 
        <termref def="unicode-normalization">Unicode Normalization</termref> if requested by the <code nobreak="false">normalization-form</code> parameter,
        and JSON escaping. JSON escaping replaces the characters 
        <char>U+005C</char>, <char>U+0008</char>, <char>U+000C</char>, <char>U+000A</char>, <char>U+000D</char>, 
         <char>U+0009</char>, or <char>U+005C</char> by the corresponding JSON escape sequences
        <code nobreak="false">\"</code>, <code nobreak="false">\b</code>, <code nobreak="false">\f</code>, <code nobreak="false">\n</code>,
          <code nobreak="false">\r</code>, <code nobreak="false">\t</code>, or <code nobreak="false">\\</code>
        respectively, and any other codepoint in the 
        range 1-31 or 127-159 by an escape in the form <code nobreak="false">\uHHHH</code> 
        where <code nobreak="false">HHHH</code> is the hexadecimal representation of the codepoint value.
          <phrase diff="add" at="2023-05-31">Escaping further replaces the solidus character (<code nobreak="false">/</code>)
          by the escape sequence <code nobreak="false">\/</code> if the <code nobreak="false">escape-solidus</code> parameter
          is set to <code nobreak="false">true</code>, but not if it is
          set to <code nobreak="false">false</code>.</phrase>
        Escaping is also applied to any characters that cannot be represented in the selected encoding.
        </p></item></olist></item><item><p>The resulting string is enclosed in double quotation marks.</p></item></olist><!--<p role="closetermdef"/>--><p>
    Finally, encoding, as controlled by the <code nobreak="false">encoding</code> parameter, 
    converts the character stream produced by the preceding rules into an octet stream. The 
    <code nobreak="false">encoding</code> parameter is ignored if <code nobreak="false">canonical</code> is <code nobreak="false">true</code>.
    
    </p></div2><div2 id="id-json-lines"><head>JSON Lines</head><p>When the <code nobreak="false">json-lines</code> parameter is set to <code nobreak="false">true</code>, the serialized
    output is written in <term>json-lines</term> format, as defined in <bibref ref="JSON-LINES"/>.</p><p>If <code nobreak="false">json-lines</code> is set to <code nobreak="false">true</code>, then each item
      in the <termref def="dt-input-value"/> is serialized indepedently as a JSON text,
      and the resulting serializations are then concatenated using a single
      <char>U+000A</char> character as a separator.
    </p><p>If <code nobreak="false">json-lines</code> and <code nobreak="false">indent</code> are both set to true, then
     the serialization of each individual item may include added <char>U+0020</char>
      and <char>U+0009</char> characters for formatting purposes, but it must not
      include <char>U+000A</char> or <char>U+000D</char> characters.</p><p>The <term>json-lines</term> specification allows <char>U+000D</char>
      characters to appear, and does not treat them as significant; however, they are likely to
      cause practical problems. For example processing such input using the XPath expression
      <code nobreak="false">unparsed-text-lines($uri) ! parse-json()</code> would fail. The serializer
      <rfc2119>MUST NOT</rfc2119> output any <char>U+000D</char> characters, either at the end
      of a line or elsewhere.</p><p>The <term>json-lines</term> specification allows a terminating
      <char>U+000A</char> character after the last line. In the interests of interoperability,
      however, the serializer <rfc2119>MUST NOT</rfc2119> output such a terminator.</p><p>If the <termref def="dt-input-value"/> is an empty sequence, then
      it is serialized as a zero-length string (rather than as the string <code nobreak="false">null</code>).</p><p>The <code nobreak="false">item-separator</code> parameter has no effect.</p></div2><div2 id="JSON_PARAMS"><head>The Influence of Serialization Parameters upon the JSON Output Method</head><p>
When nodes are serialized using the JSON output method, 
serialization is delegated to the output method specified by the 
<code nobreak="false">json-node-output-method</code> serialization parameter.  The 
<code nobreak="false">omit-xml-declaration</code> parameter is set to <code nobreak="false">true</code>, and no other 
serialization parameters are passed down to the serialization 
method responsible for serializing the node.
</p><p>The serialization parameters that affect the JSON output method are listed
    in the following subsections.</p><p>Serialization parameters other than those listed are not applicable to this output
    method.  It is the responsibility of the
    <termref def="host-language">host language</termref> to specify
    whether an error occurs if such a parameter is specified in combination
    with the JSON output method, or whether the parameter is ignored, or whether
    it is validated and then ignored.</p><div3 id="JSON_CANONICAL"><head>JSON Output Method: the <code nobreak="false">canonical</code> Parameter</head><p>The <code nobreak="false">canonical</code> parameter specifies whether the JSON output should be
      normalized to its canonical form, as specified by <bibref ref="RFC8785"/>. The
      default value is <code nobreak="false">false</code>.</p><p>If the value is <code nobreak="false">true</code> this imposes constraints on the
            representation of maps, strings, and numbers, as described in
            <specref ref="serializing-json-items"/>.
            All other parameters except
              <code nobreak="false">normalization-form</code>, <code nobreak="false">media-type</code>, <code nobreak="false">json-lines</code>,
            and <code nobreak="false">json-node-output-method</code> are ignored (except that they are passed though to
            any sub-serialization of contained nodes).</p><p>The <termref def="serializer">serializer</termref>
            <rfc2119>MUST</rfc2119> serialize the <termref def="dt-input-tree"/> according to <bibref ref="RFC8785"/>. </p><note><p><bibref ref="RFC8785"/> defines the input to canonicalization as an I-JSON text <bibref ref="RFC7493"/>.
            The rules given in <specref ref="serializing-json-items"/> effectively define how any XDM value in the 
            <termref def="dt-input-tree"/> is mapped to a value in the implicit data model of I-JSON. Values
            that cannot be mapped to I-JSON, such as function items, result in a serialization error.</p><!--<p><bibref ref="RFC8785"/> specifies a number of changes to the serialized output that
              are not otherwise addressed in this document, such as recursively sorting object
              properties lexicographically and constraining data to the I-JSON subset (<bibref ref="RFC7493"/>).</p>--></note><p>A serialization error <errorref code="0024" class="RE"/> results if any error is raised during the 
      canonicalization process.</p></div3><div3 id="JSON_ENCODING"><head>JSON Output Method: the <code nobreak="false">encoding</code> Parameter</head><p>The <code nobreak="false">encoding</code> parameter identifies the encoding that
the JSON output method
<rfc2119>MUST</rfc2119> use to convert sequences of
characters to sequences of bytes.
<termref def="serializer">Serializers</termref>
are <rfc2119>REQUIRED</rfc2119> to support values of <code nobreak="false">UTF-8</code> and
<code nobreak="false">UTF-16</code>.
A <termref def="serial-err">serialization error</termref> <errorref code="0007" class="SU"/>
occurs if the <termref def="serializer">serializer</termref>
does not support the encoding specified
by the <code nobreak="false">encoding</code> parameter.
The <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error.
  If the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> contains a
character that cannot be represented in the encoding that the
<termref def="serializer">serializer</termref> is using for output, the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119>
raise a <termref def="serial-err">serialization error</termref> 
<errorref code="0008" class="RE"/>.</p><note><p>If an encoding other than UTF-8, UTF-16, UTF-32, US-ASCII, or an
equivalent is specified for the <code nobreak="false">encoding</code> parameter, the
output will (except in unusual circumstances) fail to conform to the
definition of JSON in <bibref ref="rfc7159"/>.</p></note></div3><div3 id="JSON_INDENT"><head>JSON Output Method: the <code nobreak="false">indent</code> Parameter</head><p>The <code nobreak="false">indent</code> parameter
controls whether the <termref def="serializer">serializer</termref>
adjusts the whitespace in the serialized result so that a person will
find it easier to read. If the <code nobreak="false">indent</code> parameter has 
the value <code nobreak="false">true</code>,
the <termref def="serializer">serializer</termref> <rfc2119>MAY</rfc2119> output
additional whitespace characters adjacent to the JSON structural
tokens. For all other values, the <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> output no whitespace characters adjacent to
the JSON structural tokens.
</p><p>If <code nobreak="false">indent</code> and <code nobreak="false">json-lines</code> are both <code nobreak="false">true</code>, 
  additional whitespace is allowed, but it <rfc2119>MUST NOT</rfc2119> include
the characters <char>U+000A</char> or <char>U+000D</char>.</p></div3><div3 id="JSON_NORMALIZATION-FORM"><head>JSON Output Method: the <code nobreak="false">normalization-form</code> Parameter</head><p>The <code nobreak="false">normalization-form</code>
parameter is applicable to the JSON output method.
The values <code nobreak="false">NFC</code>
and <code nobreak="false">none</code> <rfc2119>MUST</rfc2119> be supported by the <termref def="serializer">serializer</termref>.
A <termref def="serial-err">serialization error</termref> <errorref code="0011" class="SU"/> results if the value of the
<code nobreak="false">normalization-form</code> parameter specifies a normalization form
that is not supported by the <termref def="serializer">serializer</termref>; the
<termref def="serializer">serializer</termref> <rfc2119>MUST</rfc2119> raise the
error.</p></div3><div3 id="JSON_MEDIA-TYPE"><head>JSON Output Method: the <code nobreak="false">media-type</code> Parameter</head><p>The <code nobreak="false">media-type</code> parameter is applicable to the
JSON output method.
See <specref ref="serparam"/> for more
information.</p></div3><div3 id="JSON_USE-CHARACTER-MAPS"><head>JSON Output Method: the <code nobreak="false">use-character-maps</code> Parameter</head><p>The <code nobreak="false">use-character-maps</code> parameter is applicable to the
JSON output method.
See <specref ref="character-maps"/> for more
information.</p></div3><div3 id="JSON_BYTE-ORDER-MARK"><head>JSON Output Method: the <code nobreak="false">byte-order-mark</code> Parameter</head><p>The <code nobreak="false">byte-order-mark</code> parameter is
applicable to the JSON output method.  See
<specref ref="serparam"/> for more information.</p><note><p>Serialized output containing a byte-order mark does not
conform to the definition of JSON in <bibref ref="rfc7159"/>
(although conforming JSON parsers are allowed to tolerate
the byte-order mark).</p></note></div3><div3 id="JSON_ESCAPE-SOLIDUS" diff="add" at="2023-05-31"><head>JSON Output Method: the <code nobreak="false">escape-solidus</code> Parameter</head><p>The <code nobreak="false">escape-solidus</code> parameter is
      applicable to the JSON output method. If the value is <code nobreak="false">true</code>,
      then the solidus character (<code nobreak="false">"/"</code>) appearing in a string is escaped with a backslash
      (as <code nobreak="false">"\/"</code>). If the value is <code nobreak="false">false</code>,
    then it is not escaped.</p><note><p>In previous versions of this specification, the solidus was always escaped. Although JSON does not require
  this character to be escaped, doing so provides extra safety when the generated JSON is embedded in an HTML <code nobreak="false">script</code>
  element, since an unintended <code nobreak="false">&lt;/script&gt;</code> end tag might otherwise cause the script to be prematurely
  terminated. In other situations, however, the escaping creates visual clutter and makes the output less readable.</p></note></div3><div3 id="JSON_ALLOW-DUPLICATE-NAMES"><head>JSON Output Method: the <code nobreak="false">allow-duplicate-names</code> Parameter</head><p>The <code nobreak="false">allow-duplicate-names</code> serialization parameter
determines whether the presence of multiple keys in a map item
with the same string value (e.g. the date 2014-10-01 and the string
"<code nobreak="false">2014-10-01</code>") will or will not raise serialization error
<errorref code="0022" class="RE"/>.  If the value is 
<code nobreak="false">true</code>,
such duplicate keys will result in duplicate object-member names in
the JSON output and no error will be raised because of the duplicate names.
If the value is <code nobreak="false">false</code>,
such duplicate keys are an error 
(<errorref code="0022" class="RE"/>).</p></div3><div3 id="JSON_JSON-NODE-OUTPUT-METHOD"><head>JSON Output Method: the <code nobreak="false">json-node-output-method</code> Parameter</head><p>
The <code nobreak="false">json-node-output-method</code> serialization parameter determines how a node 
  in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> gets converted to a JSON value.  
If the value is one of <code nobreak="false">xml</code>, <code nobreak="false">xhtml</code>, <code nobreak="false">html</code> or <code nobreak="false">text</code>, 
then the node is converted <termref def="to-a-json-string">to a JSON string</termref> by serializing the node using the output method 
specified by this parameter.  If the value is <code nobreak="false">xml</code> or <code nobreak="false">xhtml</code> then 
the node is serialised with the additional serialization parameter <code nobreak="false">omit-xml-declaration</code> 
set to <code nobreak="false">true</code>. All other parameters, such as <code nobreak="false">canonical</code>, remain unchanged.
</p></div3><div3 id="JSON_JSON-LINES"><head>JSON Output Method: the <code nobreak="false">json-lines</code> Parameter</head><p>The <code nobreak="false">json-lines</code> serialization parameter determines if items are serialized
according to the <bibref ref="JSON-LINES"/> format, as described in <specref ref="id-json-lines"/>.
</p></div3></div2></div1><div1 id="adaptive-output"><head>Adaptive Output Method</head><changes><change issue="1651" PR="1703" date="2025-01-14">
      The serialization of maps retains the order of entries.
    </change><change issue="2059" PR="TODO" date="2025-06-23">
      The output of QNames reflects the new syntax for QName literals.
    </change><change issue="2087 2186" PR="2114 2226" date="2025-06-22">
      A JNode is represented as <code nobreak="false">jnode(<var>K</var>: <var>V</var>)</code> where 
      <var>K</var> is its <code nobreak="false">·selector·</code> property and
      <var>V</var> is its <code nobreak="false">·content·</code> property.
    </change></changes><p>The Adaptive output method serializes the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> 
into a human readable form for the purposes of debugging query results.

The intention of this is to allow any <termref diff="chg" at="2023-11-01" def="dt-input-value"/> to be serialized 
without raising a serialization error.
Sequence normalization is not performed for this output method.
</p><p>Each item in the supplied sequence is serialized individually as
follows, with an occurrence of the chosen <code nobreak="false">item-separator</code>
between successive items.</p><ulist><item><p>A JNode is serialized as follows:</p><ulist><item><p>If the <code nobreak="false">·selector·</code> property is absent (that is, for a parentless JNode),
      in the format <code nobreak="false">jtree(<var>V</var>)</code> where <var>V</var> is the adaptive 
        serialization of the value of its <code nobreak="false">·content·</code> property.</p><p>For example, the JNode selected by the expression <code nobreak="false">jtree({ "a": [4, 5] })</code> is serialized
     as <code nobreak="false">jtree({"a":[4,5]})</code>.</p></item><item><p>If the <code nobreak="false">·selector·</code> property is present,
        then in the format <code nobreak="false">jnode(<var>K</var>: <var>V</var>)</code> where 
    <var>K</var> is the adaptive serialization of the value of its <code nobreak="false">·selector·</code> property
      and <var>V</var> is the adaptive serialization of the value of its <code nobreak="false">·content·</code> property.</p><p>For example, the JNode selected by the expression <code nobreak="false">jtree({ "a": [4, 5] })/a</code> is serialized
     as <code nobreak="false">jnode("a":[4,5])</code>.</p></item></ulist></item><item><p>A document, element, text, comment, or processing instruction
node is serialized using the XML
output method described in <specref ref="xml-output"/>.</p></item><item><p>An attribute or namespace <termref def="dt-node">node</termref> is serialized as if it had a containing
element node.  For example an
attribute node might be serialized as the string
<code nobreak="false">xsi:type="xs:integer"</code>; a namespace node might be
serialized as
<code nobreak="false">xmlns:sns="http://example.com/sample-namespace"</code>.
</p><note><p>This may result in output of QNames containing prefixes whose
binding is not displayed.</p></note></item><item><p>An <xtermref spec="XP40" ref="dt-atomic-item">atomic
item</xtermref> is serialized as follows:</p><ulist><item><p>An instance of <code nobreak="false">xs:boolean</code> is serialized as <code nobreak="false">true()</code> or <code nobreak="false">false()</code>. </p></item><item><p>An instance of <code nobreak="false">xs:string</code>, <code nobreak="false">xs:untypedAtomic</code>
 or <code nobreak="false">xs:anyURI</code>
is serialized by enclosing the value in double 
quotation marks and doubling any quotes within the value; or optionally by enclosing the value 
in apostrophes and doubling any apostrophes within the value.
The resulting value is then serialized using the Text output method 
described in <specref ref="text-output"/>.
</p><note><p>The Text output method will apply character expansion and encoding rules to this 
string as specified by the serialization parameters.</p></note></item><item><p>An instance of <code nobreak="false">xs:integer</code> or <code nobreak="false">xs:decimal</code> is serialized by converting 
the value to a string using the <code nobreak="false">fn:string</code> function.</p></item><item><p>An instance of <code nobreak="false">xs:double</code> is serialized by applying the function 
<code nobreak="false">format-number(?, '0.0##########################e0')</code>
using the following default decimal format properties:</p><table role="medium no-code-break" summary="Decimal format"><col width="180px" span="1"/><col span="1"/><thead><tr><th align="left" rowspan="1" colspan="1">Property name</th><th align="left" rowspan="1" colspan="1">Property value</th></tr></thead><tbody><tr><td rowspan="1" colspan="1"><code nobreak="false">decimal-separator</code></td><td rowspan="1" colspan="1"><char>U+002E</char></td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">exponent-separator</code></td><td rowspan="1" colspan="1"><char>U+0065</char></td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">grouping-separator</code></td><td rowspan="1" colspan="1"><char>U+002C</char></td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">zero-digit</code></td><td rowspan="1" colspan="1"><char>U+0030</char></td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">digit</code></td><td rowspan="1" colspan="1"><char>U+0023</char></td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">infinity</code></td><td rowspan="1" colspan="1">The string "INF"</td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">NaN</code></td><td rowspan="1" colspan="1">The string "NaN"</td></tr><tr><td rowspan="1" colspan="1"><code nobreak="false">minus-sign</code></td><td rowspan="1" colspan="1"><char>U+002D</char></td></tr></tbody></table></item><item><p>An instance of <code nobreak="false">xs:NOTATION</code> is serialized 
as a URI-qualified name (that is, in the form <code nobreak="false">Q{uri}local</code>).</p></item><item><p>An instance of <code nobreak="false">xs:QName</code> is serialized with a <code nobreak="false">#</code> character,
  followed by:</p><ulist><item><p>the local name if the name is in no namespace, or</p></item><item><p>the URI-qualified name otherwise (<code nobreak="false">Q{uri}local</code>).</p></item></ulist></item><item><p>An atomic item of any other type is serialized using the syntax of a constructor 
function: <code nobreak="false">xs:TYPE("VAL")</code> where <code nobreak="false">TYPE</code> is the name of the primitive 
type, and <code nobreak="false">VAL</code> is the result of applying the <code nobreak="false">fn:string()</code> function.
 For example, <code nobreak="false">xs:date("2015-07-17")</code>.
 The resulting string is then serialized using the Text output method 
described in <specref ref="text-output"/>.</p></item></ulist></item><item><p>
An <termref def="dt-array-item">array item</termref> is serialized using the syntax 
of a <xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XP40" ref="SquareArrayConstructor" xlink:type="simple"/>, 
that is as <code nobreak="false">[member, member, ... ]</code>. The members, which in general are sequences, 
are serialized in the form <code nobreak="false">(item, item, ...)</code> where the items are serialized by 
applying these rules recursively. The items are separated by commas 
(not by the <code nobreak="false">item-separator</code> character). The enclosing parentheses are optional if the sequence 
has length one. </p><note><p>The serializer should avoid outputting the parentheses if it is able 
to determine the length of the sequence before serializing the first item; but it is allowed 
to output parentheses around a singleton if this avoids buffering data in memory.</p></note></item><item><p>
A <termref def="dt-map-item">map item</termref> is serialized using the syntax of a 
<xspecref spec="XP40" ref="doc-xpath40-MapConstructor"/> without the optional <code nobreak="false">map</code>
keyword, that is in the format <code nobreak="false">{key:value, key:value, ...}</code>.
The key/value pairs in the serialized output retain the 
  <xtermref spec="DM40" ref="dt-entry-order">entry order</xtermref> of entries in the map.
   The key is serialized by applying the rules 
for serializing an atomic item. The values are serialized in the same way as the members of an array (see above).
</p></item><item><p>A <termref def="dt-function-item">function item</termref> is
serialized to the representation <code nobreak="false">name#A</code> where 
<var>fn:name</var> is a representation of
the function name and <var>A</var> is the arity. 
If the function name is in one of the namespaces
<code nobreak="false">http://www.w3.org/2005/xpath-functions</code>,
<code nobreak="false">http://www.w3.org/2005/xpath-functions/math</code>,
<code nobreak="false">http://www.w3.org/2005/xpath-functions/map</code>,
<code nobreak="false">http://www.w3.org/2005/xpath-functions/array</code> or
<code nobreak="false">http://www.w3.org/2001/XMLSchema</code>,
then the name is output as a lexical QName using the conventional prefix 
<code nobreak="false">fn</code>, <code nobreak="false">math</code>, <code nobreak="false">map</code>, <code nobreak="false">array</code>, or <code nobreak="false">xs</code>
as appropriate; if it is in any other namespace or in no namespace, then the name is 
output as a URI-qualified name (that is, <code nobreak="false">Q{uri}local</code>).
 
If the function is anonymous,
<var>name</var> is replaced by the string
<code nobreak="false">(anonymous-function)</code>.  </p><note><p>
The following examples illustrate this rule:</p><ulist><item><p><code nobreak="false">fn:exists#1</code> is serialized as <code nobreak="false">function fn:exists#1</code></p></item><item><p><code nobreak="false">Q{http://www.w3.org/2005/xpath-functions}exists#1</code> is serialized as <code nobreak="false">fn:exists#1</code></p></item><item><p><code nobreak="false">function($a) { $a }</code> is serialized as <code nobreak="false">(anonymous-function)#1</code></p></item><item><p><code nobreak="false">math:pi#0</code> is serialized as <code nobreak="false">math:pi#0</code></p></item></ulist></note></item></ulist><p>Character maps are applied (a) when nodes are serialized using the XML 
output method, and (b) to any value represented as a string enclosed in quotation marks.</p><p>Optionally, in all the above constructs, characters whose visual 
representation is ambiguous (for example tab or non-breaking-space) may be represented in the 
form of an XML numeric character reference (for example <code nobreak="false">&amp;#x9;</code> or <code nobreak="false">&amp;#xa0;</code>)</p><note><p>
In many cases the serialization of an item conforms to the syntax of an XQuery expression whose result 
is that item. There are exceptions, however. For example, the syntax will not be valid XQuery in the 
case of free-standing attribute or namespace nodes, or QName values, or anonymous functions; and where 
it is valid XQuery, the result of evaluating the expression will not necessarily be identical to the 
original: for example, the distinction between strings and untypedAtomic items is lost.
</p></note><p>
If any value cannot be output because doing so would cause a
serialization error, the behavior is <termref def="impdef">implementation-defined</termref>.
</p><imp-def-feature>It is <termref def="impdef">implementation-defined</termref> whether the
serialization process recovers from serialization errors when the
Adaptive output method is used.  If it does, it
is <termref def="impdef">implementation-defined</termref> what error
indicator is used.</imp-def-feature><p>
If the output is sent to a destination that allows hyperlinks to be included in the 
generated text, then the serializer <rfc2119>MAY</rfc2119> include 
<termref def="impdep">implementation-dependent</termref> 
hyperlinks to provide additional information for example:</p><ulist><item><p>
to allow the type of <xtermref spec="XP40" ref="dt-atomic-item">atomic items</xtermref>
to be ascertained.
</p></item><item><p>
to allow the namespace binding of prefixes to be ascertained.
</p></item><item><p>
to provide further information about the cause of error indicators.
</p></item></ulist><imp-def-feature>It is <termref def="impdef">implementation-defined</termref> whether, when the
Adaptive output method is used, a serializer includes hyperlinks in
its output to record the types of atomic items, the bindings of
namespace prefixes, the causes of error indicators, and other
information.
</imp-def-feature><imp-dep-feature>If, when the
Adaptive output method is used, a serializer includes hyperlinks in
its output to record the types of atomic items, the bindings of
namespace prefixes, the causes of error indicators, and other
information, then it is <termref def="impdep">implementation-dependent</termref> what hyperlinks are
used and how they convey the information.
</imp-dep-feature><div2 id="ADAPTIVE_PARAMS"><head>The Influence of Serialization Parameters upon the Adaptive Output Method</head><changes><change issue="530" PR="534" date="2023-06-06">
      Added the <code nobreak="false">escape-solidus</code> parameter for JSON serialization.
    </change></changes><p>
For some item types the Adaptive output method will delegate serialization to other output methods. 
With the exception of the <code nobreak="false">byte-order-mark</code> serialization parameter, all serialization parameters, 
if set, will be passed down to the serialization method that is applied to each item in the supplied sequence. 
Only the <code nobreak="false">item-separator</code> and <code nobreak="false">byte-order-mark</code> parameters are directly applicable to the Adaptive output method. 
</p><div3 id="ADAPTIVE_OMIT-XML-DECLARATION"><head>Adaptive Output Method: the <code nobreak="false">omit-xml-declaration</code> and <code nobreak="false">standalone</code> Parameters</head><p>The <code nobreak="false">omit-xml-declaration</code> and <code nobreak="false">standalone</code>
parameters are not directly applicable to the Adaptive output
method.</p><note><p>
If these parameters call for an XML declaration to be serialized, then
an XML declaration is to be output each time the Adaptive output
method delegates the serialization of a node to the XML output method.
If several node items appear in the sequence to be serialized or as
values in maps or arrays to be serialized, then the output will
contain several XML declarations.  
<!--* (This may be the desired behavior
if later processes will split the output and send different parts to
different destinations.  If it is not the desired output, the user
can change the parameter values.) *-->
</p></note></div3><div3 id="ADAPTIVE_USE-CHARACTER-MAPS"><head>Adaptive Output Method: the <code nobreak="false">use-character-maps</code> Parameter</head><p>The <code nobreak="false">use-character-maps</code> parameter is applicable to the
Adaptive output method only as elsewhere specified.
</p></div3><div3 id="ADAPTIVE_BYTE-ORDER-MARK"><head>Adaptive Output Method: the <code nobreak="false">byte-order-mark</code> Parameter</head><p>The <code nobreak="false">byte-order-mark</code> parameter is applicable to the
Adaptive output method. See
<specref ref="serparam"/> for more information.
</p><note><p>A byte order mark can appear only once in the serialized output.
Therefore, this parameter does not get passed down to any delegated output method.</p></note></div3><div3 id="ADAPTIVE_ESCAPE-SOLIDUS" diff="add" at="2023-05-31"><head>Adaptive Output Method: the <code nobreak="false">escape-solidus</code> Parameter</head><p>The <code nobreak="false">escape-solidus</code> parameter is
    applicable to the Adaptive output method only as elsewhere specified.</p></div3><div3 id="ADAPTIVE_ITEM-SEPARATOR"><head>Adaptive Output Method: the <code nobreak="false">item-separator</code> Parameter</head><p>The <code nobreak="false">item-separator</code> serialization parameter is directly applicable to the
Adaptive output method. It specifies the string to be inserted between
adjacent serialized items.
 If the <code nobreak="false">item-separator</code> parameter is absent, the character <char>U+000A</char>
 is used by the Adaptive output method as the 
 <code nobreak="false">item-separator</code> value.

</p></div3></div2></div1><div1 id="character-maps"><head>Character Maps</head><p>The <code nobreak="false">use-character-maps</code> parameter is a list of characters
and corresponding string substitutions.</p><p>Character maps allow a specific character appearing in a text or
attribute node or a string 
in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/> to be replaced with a specified
string of characters during serialization. The string that is
substituted is output "as is," and the <termref def="serializer">serializer</termref> performs no checks
that the resulting document is well-formed. This mechanism can
therefore be used to introduce arbitrary markup in the serialized
output.
See <xspecref spec="XT40" ref="character-maps"/>
of <bibref ref="xslt-40"/> for examples of using character mapping in
XSLT.</p><p>Character mapping is applied to the characters that actually appear
in a text or attribute node or a string
in the <termref diff="chg" at="2023-11-01" def="dt-input-tree"/>, before any other
serialization operations such as escaping or <termref def="unicode-normalization">Unicode Normalization</termref> are
applied. If a character is mapped, then it is not subjected to XML or
HTML escaping, nor to Unicode Normalization. The string that is
substituted for a character is not validated or processed in any way
by the <termref def="serializer">serializer</termref>, except for translation into the target encoding. In
particular, it is not subjected to XML or HTML escaping, it is not
subjected to Unicode Normalization, and it is not subjected to further
character mapping.  </p><p>Character mapping is not applied to characters in text nodes whose
parent elements are listed in the <code nobreak="false">cdata-section-elements</code>
parameter,

nor to characters for which output escaping has
been disabled (disabling output escaping is an <bibref ref="xslt-40"/>
feature),

nor to characters in attribute
values that are subject to <termref def="uri-escaping">URI escaping</termref> defined for the HTML and
XHTML output methods, unless <termref def="uri-escaping">URI escaping</termref> has been disabled using the
<code nobreak="false">escape-uri-attributes</code> parameter in the output
definition.</p><p>On serialization, occurrences of a character specified in the
<code nobreak="false">use-character-maps</code> in text nodes, attribute values
and strings
are replaced by the corresponding string from the <code nobreak="false">use-character-maps</code>
parameter.</p><note><p>Using a character map can result in non-well-formed documents
if the string contains XML-significant
characters. For example, it is possible to create documents containing
unmatched start and end tags, references to entities that are not
declared, or attributes that contain tags or unescaped quotation
marks.</p></note><p>If a character is mapped, then it is not subjected to XML or HTML escaping.</p><p>A <termref def="serial-err">serialization error</termref> <errorref code="0008" class="RE"/> occurs if character mapping causes the output
of a string containing a character that cannot be represented in the
encoding that the <termref def="serializer">serializer</termref>
is using for output. The <termref def="serializer">serializer</termref>
<rfc2119>MUST</rfc2119> raise the error.</p></div1><div1 id="conformance"><head>Conformance</head><p>Serialization is intended primarily as a component
of a <termref def="host-language">host language</termref>.
<termdef term="host language" id="host-language">
A <term>host language</term> is another
specification that includes, by reference, this specification and all of
its requirements.  A host language might be a programming language
such as <bibref ref="xslt-40"/> or <bibref ref="xquery-40"/>, or it
might be an application programming interface (API) intended to be used by
programs written in some other high-level programming language.  The use of
the term <emph>language</emph> is not intended to preclude the possibility that
this specification might be referenced outside the context of a
programming language specification.</termdef>
This document
relies on specifications that use it to specify conformance criteria
for Serialization in their respective environments.
Specifications that set conformance criteria for their use of
Serialization <rfc2119>MUST NOT</rfc2119> change the semantic definitions of 
Serialization as given in this specification, except by
subsetting and/or compatible extensions.  It is the responsibility of the <termref def="host-language">host language</termref> to specify how <termref def="serial-err">serialization errors</termref>
are to
be handled.</p><p>Certain facilities in this specification are described as producing 
<termref def="impdef">implementation-defined</termref> results. A
claim that asserts conformance with this specification <rfc2119>MUST</rfc2119> be accompanied by documentation
stating the effect of each implementation-defined feature. For convenience, a non-normative
checklist of implementation-defined features is provided at 
<specref ref="implementation-defined-features"/>.</p></div1></body><back><div1 id="references"><head>References</head><div2 id="normative-references"><head>Normative References</head><blist><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="canonical-xml-1-1" key="Canonical XML 1.1" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="charmod-norm" key="Character Model for the World Wide Web 1.0: Normalization" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xpath-datamodel-40" key="XDM 4.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xpath-functions-40" key="Functions and Operators 4.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="html5" key="HTML5" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="html401" key="HTML" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="html-polyglot" key="POLYGLOT" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="IANA" key="IANA" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC2046" key="RFC2046" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC2119" key="RFC2119" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC2978" key="RFC2978" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC2854" key="RFC2854" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC3236" key="RFC3236" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC7493" key="RFC7493" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC8785" key="RFC8785" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="UNICODE-ENCODING" key="Unicode Encoding" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
<titleref href="http://www.unicode.org/reports/tr17/" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Unicode
Character Encoding Model</titleref>,
Unicode Consortium.
Unicode Standard Annex #17.
</bibl><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="UNICODE-NORMALIZATION-FORM" key="UAX #15: Unicode Normalization Forms" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
<titleref href="http://www.unicode.org/reports/tr15/" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">Unicode
Normalization Forms</titleref>,
Unicode Consortium.
Unicode Standard Annex #15.
</bibl><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="JSON-LINES" key="JSON Lines" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
<titleref href="https://jsonlines.org/" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">JSON Lines</titleref>.
Maintained by Ian Ward.
</bibl><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xhtml1" key="XHTML 1.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xhtml11" key="XHTML 1.1" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xml" key="XML10" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xml11" key="XML11" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xml-names" key="XML Names" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xml-names11" key="XML Names 1.1" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xmlschema-1" key="XML Schema" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xpath-40" key="XPath 4.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xquery-40" key="XQuery 4.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xslt-40" key="XSLT 4.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xx-ECMA-404" key="The JSON Data Interchange Format" diff="del" at="2014-09-22" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
<titleref href="http://www.ecma-international.org/publications/standards/Ecma-404.htm" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">The JSON Data Interchange Format</titleref>,
ECMA International.
</bibl><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="rfc7159" key="RFC 7159" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">IETF. 
<emph>RFC 7159: The Javascript Object Notation (JSON) Data Interchange Format</emph><phrase diff="add" at="2014-09-22">,
T. Bray, Editor.
Internet Engineering Task Force, March 2014.</phrase>
Available at:
<loc href="http://www.rfc-editor.org/rfc/rfc7159.txt" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.rfc-editor.org/rfc/rfc7159.txt</loc>
</bibl></blist></div2><div2 id="informative-references"><head>Informative References</head><blist><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="ECMA-404" key="The JSON Data Interchange Format" diff="add" at="2014-09-22" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
<titleref href="http://www.ecma-international.org/publications/standards/Ecma-404.htm" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">The JSON Data Interchange Format</titleref>,
ECMA International.
</bibl><!-- Added in response to qt-2004Feb0362-16 --><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xhtml-modularization" key="XHTML Modularization" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><!-- bibl id="xhtml-media-types" key="XHTML Media Types W3C Note 1 August 2002">
  World Wide Web Consortium,
  <emph>XHTML Media Types W3C Note 1 August 2002</emph>
  See <loc href="http://www.w3.org/TR/xhtml-media-types/">http://www.w3.org/TR/xhtml-media-types/</loc>.</bibl --><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xpath-datamodel" key="XDM 4.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="serialization-10-2ed" key="XSLT 2.0 and XQuery 1.0 Serialization (Second Edition)" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
      <titleref href="http://www.w3.org/TR/2010/REC-xslt-xquery-serialization-20101214/" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XSLT 2.0 and XQuery 1.0 Serialization (Second Edition), W3C Recommendation</titleref>, 
   Henry Zongaro, Norman Walsh, Joanne Tong, <emph>et. al.</emph>, Editors. 
   World Wide Web Consortium, 14  December  2010. 
   This version is http://www.w3.org/TR/2010/REC-xslt-xquery-serialization-20101214/</bibl><bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="serialization-40-fpwd" key="XSLT and XQuery Serialization 4.0 (First Public Working Draft)" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
     <titleref href="http://www.w3.org/TR/2014/WD-xslt-xquery-serialization-40-20140424/" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">XSLT and XQuery 
     Serialization, W3C First Public Working Draft</titleref>, 
     Andrew Coleman, C. M. Sperberg-McQueen, <emph>et. al.</emph>, Editors. 
   World Wide Web Consortium, 24 April 2014.</bibl></blist></div2></div1><div1 id="serparams-schema"><head>Schema for Serialization Parameters</head><p>The following schema describes the structure of a <termref def="dt-parameter-document"/>
that can be used to specify the settings of serialization parameters using
the mechanism described in <specref ref="serparams-in-xdm-instance"/>.</p><p>A copy of this schema is available at
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2017/01/xslt-xquery-serialization/schema-for-serialization-parameters.xsd" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/2017/01/xslt-xquery-serialization/schema-for-serialization-parameters.xsd</loc>.</p><?schema-for-params?></div1><div1 id="id-errors"><head>Summary of Error Conditions</head><p>This document uses the <code nobreak="false">err</code> prefix which represents the
same namespace URI (http://www.w3.org/2005/xqt-errors) as defined in
<bibref ref="xpath-40" diff="chg" at="2013-12-07"/>.  Use of this
namespace prefix binding in this document is not normative.</p><error-list><error code="0001" class="NR" type="serialization" spec="SE"><p>It is an error if an item in <emph>S<sub>6</sub></emph> in <termref def="sequence-normalization">sequence normalization</termref> is an
attribute node, a namespace node, or a
<termref def="dt-function-item">function</termref>.</p></error><error spec="SE" code="0003" class="RE" type="serialization"><p>It is an error if the <termref def="serializer">serializer</termref> is unable to satisfy the rules
for either a well-formed XML document entity or a well-formed XML
external general parsed entity, or both, except for content modified
by the character expansion phase of serialization.</p></error><error spec="SE" code="0004" class="PM" type="serialization"><p>It is an error to specify the doctype-system parameter, or to
specify the standalone parameter with a value other than
<code nobreak="false">omit</code>, if the instance of the data model contains text
nodes or multiple element nodes as children of the root
node.</p></error><error spec="SE" code="0005" class="RE" type="serialization"><p>It is an error if the serialized result would contain an
<xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="Names" ref="NT-NCName" xlink:type="simple">NCName</xnt> that contains a character that is not
permitted by the version of Namespaces in XML specified by the
<code nobreak="false">version</code> parameter.</p></error><error spec="SE" code="0006" class="RE" type="serialization"><p>It is an error if the serialized result would contain a character
that is not permitted by the version of XML specified by the
<code nobreak="false">version</code> parameter.</p></error><error spec="SE" code="0007" class="SU" type="serialization"><p>It is an error if an output encoding other than <code nobreak="false">UTF-8</code>
or <code nobreak="false">UTF-16</code> is requested and the <termref def="serializer">serializer</termref> does not support that
encoding.</p></error><error spec="SE" code="0008" class="RE" type="serialization"><!--Should this be merged with 0015 into a more generic error?--><p>It is an error if a character that cannot be represented in the
encoding that the <termref def="serializer">serializer</termref> is
using for output appears in a context where character references are
not allowed (for example if the character occurs in the name of an
element).</p></error><error spec="SE" code="0009" class="PM" type="serialization"><p>It is an error if the <code nobreak="false">omit-xml-declaration</code> parameter
has the value <code nobreak="false">yes</code>, 
<phrase diff="add" at="2016-07-07"><code nobreak="false">true</code> or <code nobreak="false">1</code></phrase>,
and the <code nobreak="false">standalone</code>
attribute has a value other than <code nobreak="false">omit</code>; or the
<code nobreak="false">version</code> parameter has a value other than <code nobreak="false">1.0</code>
and the <code nobreak="false">doctype-system</code> parameter is
specified.</p></error><error spec="SE" code="0010" class="PM" type="serialization"><p>It is an error if the output method is <code nobreak="false">xml</code> or
<code nobreak="false">xhtml</code>, the value of the <code nobreak="false">undeclare-prefixes</code>
parameter is 
<phrase diff="add" at="2016-07-07">one of</phrase>
<code nobreak="false">yes</code>,
<phrase diff="add" at="2016-07-07"> <code nobreak="false">true</code> or <code nobreak="false">1</code></phrase>,
and the value of the
<code nobreak="false">version</code> parameter is 1.0.</p></error><error spec="SE" code="0011" class="SU" type="serialization"><p>It is an error if the value of the <code nobreak="false">normalization-form</code>
parameter specifies a normalization form that is not supported by the
<termref def="serializer">serializer</termref>.</p></error><error spec="SE" code="0012" class="RE" type="serialization"><p>It is an error if the value of the <code nobreak="false">normalization-form</code>
parameter is <code nobreak="false">fully-normalized</code> and any relevant construct
of the result begins with a combining character.</p></error><error spec="SE" code="0013" class="SU" type="serialization"><p>It is an error if the <termref def="serializer">serializer</termref> does not support the version of
XML or HTML specified by the <code nobreak="false">version</code> parameter.</p></error><error spec="SE" code="0014" class="RE" type="serialization"><p>It is an error to use the HTML output method if characters which
are permitted in XML but not in HTML appear in the instance of the
data model.</p></error><error spec="SE" code="0015" class="RE" type="serialization"><p>It is an error to use the HTML output method when <code nobreak="false">&gt;</code>
appears within a processing instruction in the data model instance
being serialized.</p></error><error spec="SE" code="0016" class="PM" type="serialization"><p>It is an error if a parameter value is invalid for the defined
domain.</p></error><error spec="SE" code="0017" class="PM" type="serialization"><p>It is an error if evaluating an expression in order to extract the
setting of a serialization parameter from a data model instance would
yield an error.</p></error><error spec="SE" code="0018" class="PM" type="serialization"><p>It is an error if evaluating an expression in order to extract the
setting of the <code nobreak="false">use-character-maps</code> serialization parameter
from a data model instance would yield a sequence of length greater
than one.</p></error><error spec="SE" code="0019" class="PM" type="serialization"><p>It is an error if an instance of the data model used to specify the
settings of serialization parameters specifies the value of the same
parameter more than once.</p></error><error spec="SE" code="0020" class="RE" type="serialization" diff="add" at="2014-09-22"><p>It is an error if a numeric value being serialized using the 
JSON output method cannot be represented in the JSON grammar
(e.g. <code nobreak="false">+INF</code>, <code nobreak="false">-INF</code>, <code nobreak="false">NaN</code>).
</p></error><error spec="SE" code="0021" class="RE" type="serialization" diff="add" at="2014-09-22"><p>It is an error if a sequence being serialized using the JSON output
method includes items for which no rules are provided in the
appropriate section of the serialization rules.</p></error><error spec="SE" code="0022" class="RE" type="serialization" diff="add" at="2014-09-22"><p>It is an error if a map being serialized using the JSON output method
has two keys with the same string value, unless the 
<code nobreak="false">allow-duplicate-names</code> has the value
<code nobreak="false">yes</code>,
<phrase diff="add" at="2016-07-07"> <code nobreak="false">true</code> or <code nobreak="false">1</code></phrase>.</p></error><error spec="SE" code="0023" class="RE" type="serialization" diff="add" at="2014-11-06"><p>It is an error if a sequence being serialized using the JSON output
method is of length greater than one.</p></error><error spec="SE" code="0024" class="RE" type="serialization" diff="add" at="2025-11-14"><p>It is an error if the processing the rules for canonicalization result in a 
    serialization failure.</p></error></error-list></div1><div1 id="list-of-uri-attributes"><head>List of URI Attributes</head><p>The following list of attributes are declared as type <code nobreak="false">%URI</code> or 
  <code nobreak="false">%UriList</code> for a given HTML or XHTML element, with the exception of the 
  <code nobreak="false">name</code> attribute for element <code nobreak="false">A</code> which is not a URI type.  
  The <code nobreak="false">name</code> attribute for element <code nobreak="false">A</code> <rfc2119>SHOULD</rfc2119> be escaped as is
  recommended by the HTML Recommendation <bibref ref="html401"/> in Appendix B.2.1.</p><table role="medium no-code-break" width="500px" summary="Attributes of type URI"><col width="200px" span="1"/><col width="300px" span="1"/><thead><tr><th align="left" rowspan="1" colspan="1">Attributes</th><th align="left" rowspan="1" colspan="1">Elements</th></tr></thead><tbody><tr><td rowspan="1" colspan="1">action</td><td rowspan="1" colspan="1">FORM</td></tr><tr><td rowspan="1" colspan="1">archive</td><td rowspan="1" colspan="1">OBJECT</td></tr><tr><td rowspan="1" colspan="1">background</td><td rowspan="1" colspan="1">BODY</td></tr><tr><td rowspan="1" colspan="1">cite</td><td rowspan="1" colspan="1">BLOCKQUOTE, DEL, INS, Q</td></tr><tr><td rowspan="1" colspan="1">classid</td><td rowspan="1" colspan="1">OBJECT</td></tr><tr><td rowspan="1" colspan="1">codebase</td><td rowspan="1" colspan="1">APPLET, OBJECT</td></tr><tr><td rowspan="1" colspan="1">data</td><td rowspan="1" colspan="1">OBJECT</td></tr><tr><td rowspan="1" colspan="1">datasrc</td><td rowspan="1" colspan="1">BUTTON, DIV, INPUT, OBJECT, SELECT, SPAN, TABLE, TEXTAREA</td></tr><tr><td rowspan="1" colspan="1">for</td><td rowspan="1" colspan="1">SCRIPT</td></tr><tr><td rowspan="1" colspan="1">formaction</td><td rowspan="1" colspan="1">BUTTON, INPUT</td></tr><tr><td rowspan="1" colspan="1">href</td><td rowspan="1" colspan="1">A, AREA, BASE, LINK</td></tr><tr><td rowspan="1" colspan="1">icon</td><td rowspan="1" colspan="1">COMMAND</td></tr><tr><td rowspan="1" colspan="1">longdesc</td><td rowspan="1" colspan="1">FRAME, IFRAME, IMG</td></tr><tr><td rowspan="1" colspan="1">manifest</td><td rowspan="1" colspan="1">HTML</td></tr><tr><td rowspan="1" colspan="1">name</td><td rowspan="1" colspan="1">A</td></tr><tr><td rowspan="1" colspan="1">poster</td><td rowspan="1" colspan="1">VIDEO</td></tr><tr><td rowspan="1" colspan="1">profile</td><td rowspan="1" colspan="1">HEAD</td></tr><tr><td rowspan="1" colspan="1">src</td><td rowspan="1" colspan="1">AUDIO, EMBED, FRAME, IFRAME, IMG, INPUT, SCRIPT, SOURCE, TRACK, VIDEO</td></tr><tr><td rowspan="1" colspan="1">usemap</td><td rowspan="1" colspan="1">IMG, INPUT, OBJECT</td></tr><tr><td rowspan="1" colspan="1">value</td><td rowspan="1" colspan="1">INPUT</td></tr></tbody></table></div1><inform-div1 id="id-glossary"><head>Glossary</head><!-- This processing instruction automatically generates the glossary. --><?glossary?></inform-div1><inform-div1 id="implementation-defined-or-dependent-features"><head>Checklist of Implementation-Defined and Implementation-Dependent Features</head><p>This appendix provides a summary of Serialization features whose
  effect is explicitly 
  <termref def="impdef">implementation-defined</termref> or <termref def="impdep">implementation-dependent</termref>.</p><div2 id="implementation-defined-features"><head>Checklist of Implementation-Defined Features</head><p>The following list describes
  Serialization features whose effect is explicitly <termref def="impdef">implementation-defined</termref>.  The conformance
  rules (see <specref ref="conformance"/>) require vendors to provide
  documentation that explains how these choices have been
  exercised.</p><?imp-def-feature?></div2><div2 id="implementation-dependent-features"><head>Checklist of Implementation-Dependent Features</head><p>The following list describes Serialization features whose effect is
  explicitly <termref def="impdep">implementation-dependent</termref>.
  The conformance rules (see <specref ref="conformance"/>) do not require vendors
  or specifications which define conformance criteria for serialization
  to provide documentation that explains how these choices have been exercised.</p><?imp-dep-feature?></div2></inform-div1><inform-div1 id="revision-log" diff="chg" at="2023-02-09"><head>Change Log</head><p>This appendix lists changes made in version 4.0 of this specification.</p><?change-log?></inform-div1><inform-div1 id="back-compatibility" diff="chg" at="A"><head>Backward compatibility</head><p>This section summarizes the extent to which this specification is compatible with previous versions.</p><p>Version 4.0 is fully backwards compatible with version 3.1, except as noted below:</p><olist><item diff="add" at="issue2059"><p>The output of QNames with the <specref ref="adaptive-output"/> has been adapted to
            reflect the new QName literal syntax: QName strings are now prefixed with
            the <code nobreak="false">#</code> character.</p></item></olist></inform-div1></back></spec><!--XSLT Processor: Saxonica-->