output method in serialization properties when no xsl:output is present
Added by Martin Honnen over 4 years ago
Using Saxon 9.9.1.7, on both Java and .NET, I am trying to capture serialization properties Saxon applies to result documents created with xsl:result-document
, by subclassing Serializer
(the Java class) and overriding getReceiver
to capture the second parameter in a field.
This works for most tests I have run, but one example where there is no xsl:output
present and the xsl:result-document
also have no serialization or format attributes, while Saxon serializes everything as XML, the serialization properties don't have any method
set.
Example is
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="root/*">
<xsl:next-match/>
<xsl:result-document href="{local-name()}.xml">
<xsl:copy-of select="."/>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
An input sample would be
<?xml version="1.0" encoding="UTF-8"?>
<root>
<foo>foo</foo>
<bar>bar</bar>
</root>
I first though, that no xsl:output
being specified, that no method
is propagated to the SerializationProperties. However, a slight change to the XSLT in the form of
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="root/*">
<xsl:next-match/>
<xsl:result-document href="{local-name()}.xml">
<result>
<xsl:copy-of select="."/>
</result>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
and suddenly the SerializationProperties know about method
being xml
.
Why is the method not being reported as xml
for the first sample?
Replies (1)
RE: output method in serialization properties when no xsl:output is present - Added by Michael Kay over 4 years ago
The default serialization method (xml, xhtml, html), as far as the spec is concerned, is determined dynamically, based on the name of the outermost element in the result tree. Saxon attempts to establish it statically where it is able to do so: in your second example, the name of the root element in the result tree is known statically, in the first example this is not the case.
The dynamic rule is an awful nuisance for the processor, because the way processing instructions are serialized varies by output method, and processing instructions can appear before the output method is known...
Please register to reply