omit-xml-declaration for adaptive serialization
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 (https://www.w3.org/TR/xslt-30/#element-output):
"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" (https://www.w3.org/TR/xquery-31/#id-impl-defined-items), says that the default is implementation-defined:
"The following items in this specification are implementation-defined: [...]
- 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 http://www.saxonica.com/documentation/index.html#!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
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
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.
#4 Updated by Debbie Lockett 9 months ago
- Status changed from New to In Progress
"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.
Please register to edit this issue