Bug #4647

omit-xml-declaration for adaptive serialization

Added by Debbie Lockett about 1 year ago. Updated 3 months ago.

Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
10, 9.9
Fix Committed on Branch:
10, trunk
Fixed in Maintenance Release:


For adaptive serialization, setting the omit-xml-declaration parameter has no affect. XML declarations are never output when serializing nodes, so in effect the default is "true", and setting the parameter to "false" has no affect (i.e. this does not force XML declarations to be included).

For instance, try amending the XSLT30 test result-document-0304. The test was relatively recently amended to explicitly set omit-xml-declaration="true" on the xsl:result-document instruction. Removing the parameter, or changing it to set omit-xml-declaration="false" has no affect on the result.

Note that the expected default depends on where the serialization comes from.

The XSLT 3.0 specification says that the default for omit-xml-declaration is false (

"The value of the omit-xml-declaration attribute provides the value of the omit-xml-declaration parameter to the serialization method. The default value is no."

Meanwhile the XQuery 3.1 specification, under "D. Implementation-Defined items" (, says that the default is implementation-defined:

"The following items in this specification are implementation-defined: [...]

  1. The default values for the byte-order-mark, encoding, html-version, item-separator, media-type, normalization-form, omit-xml-declaration, standalone, and version parameters, if the Serialization Feature is supported."

(And the Saxon documentation does not explicitly state what these defaults are at!conformance/xquery31)

While the specification for the fn:serialize function, says the default for omit-xml-declaration is different again: (

"If the second argument is omitted, or is supplied in the form of an output:serialization-parameters element, then the values of any serialization parameters that are not explicitly specified is ·implementation-defined·, and may depend on the context."

"If the second argument is supplied as a map [...] The required type of each parameter, and its default value, are defined by the following table." And the table says that here the default for omit-xml-declaration is "yes" i.e. true()."


#1 Updated by Michael Kay about 1 year ago

The spec for the adaptive method is a bit illogical here. "The encoding parameter is not directly applicable to the Adaptive output method." (so what encoding should it use?) but the encoding presumably finds its way into any XML declarations included in the result, whether or not that encoding is the one actually used.

I thing the reason fn:serialize() defaults omit-xml-declaration to "yes" is that the output of fn:serialize() is a string, therefore it has no particular encoding, and therefore any XML declaration would be misleading.

#2 Updated by Debbie Lockett 12 months ago

The section "10.1 The Influence of Serialization Parameters upon the Adaptive Output Method" in the serialization spec begins by saying:

"For some item types the Adaptive output method will delegate serialization to other output methods. With the exception of the byte-order-mark 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 item-separator and byte-order-mark parameters are directly applicable to the Adaptive output method."

So yes, the encoding, like other serialization properties, should be passed down and used.

#3 Updated by Michael Kay 10 months ago

Test output-0721 uses the adaptive method; it does not specify a value of omit-xml-declaration, but the expected results expect the XML declaration to be absent. Saxon-JS is failing this test; I believe the test is incorrect.

#4 Updated by Debbie Lockett 9 months ago

  • Status changed from New to In Progress

In AdaptiveEmitter.serializeNode(), the "omit-xml-declaration" property is unconditionally being set to "yes". This is why setting the output parameter has no affect (it is always overwritten). This code should be patched to only set "omit-xml-declaration" to the required default if the output parameter has not already been specified.

As discussed above, the XSLT 3.0 specification in fact states that the default for omit-xml-declaration should be false; while for XQuery 3.1 the default is implementation defined. It is easiest and most consistent if we use the same default for XSLT and XQuery.

Making this change shows up other test issues, namely for the QT3 method-adaptive tests Serialization-adaptive-06, -07, -08, -09, -10, -20, -27. These tests each run a query where omit-xml-declaration is not specified, but the result expects the XML declaration to be absent. Like XSLT 3.0 output-0721, I think these tests are incorrect.

#5 Updated by Debbie Lockett 9 months ago

  • Status changed from In Progress to Resolved

QT3 method-adaptive tests amended to allow optional XML declaration when serializing nodes.

Patch committed in AdaptiveEmitter class on 10.x and 11.x trunk branches.

#6 Updated by O'Neil Delpratt 3 months ago

  • Fix Committed on Branch 10, trunk added

#7 Updated by O'Neil Delpratt 3 months ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.5 added

Bug fix applied to Saxon 10.5 maintenance release.

Please register to edit this issue

Also available in: Atom PDF