Serializer.SetOutputWriter seems to ignore omit-xml-declaration setting [Saxon-HE 126.96.36.199N]
In one particular case, we use an
XmlReader as input and a
StringWriter as output to the transformation. The intent is to gather a bunch of XML fragments (that may not be well-formed, due to being empty, plain-text or having multiple root elements) from complete (and well-formed) documents, glue them together in our code, and act further on that.
With 188.8.131.52N, the XML fragment created contains an XML-Declaration, even when the XSLT specifies @omit-xml-declaration="yes"@. This didn't happen with 9.5, and is a problem since we assume that after glueing them together (and wrapping it in a root element), we can parse the whole thing as XML (best case we get a list of XML elements within our artificial root; worst case we get our root element with one huge plain-text node).
This fails on our side since the root element contains a bunch of XML-Declarations.
Please see the attached sample code for a reproduction case.
In the sample, I simply pass a static '@@' and want to produce a static '@@' for further use.
However, what the transformation actually returns is '@<?xml version="1.0" encoding="UTF-8"?>@' (that backslash is placed intentionally and not part of the output, but otherwise the @ formatting seemed to eat the declaration).
The used XSL fragment is in the sample (as a comment), but I'll replicate it here aswell (i tried to keep it as straight-forward as possible for the sake of showing the problem; changing the XSLT Version or using different xsl:output options does not seem to change anything):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/"><output1/><output2/></xsl:template> </xsl:stylesheet>
In the code itself, it makes no difference using a
TextWriter@, @FileStream or @MemoryStream@.
#3 Updated by O'Neil Delpratt about 7 years ago
Hi, I am still investigating the cause of the omit-xml-declaration option being ignored. It seems that the default option in the Serializer is over riding what is set in the stylesheet.
As a workaround you could do the following on the Serializer object in your code:
destination.SetOutputProperty(new QName(omit-xml-declaration), "yes");
#4 Updated by O'Neil Delpratt about 7 years ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
Bug fixed and committed to subversion. The problem was the default output properties from the executable of the stylesheeet were not been passed to the Serializer destination.
Change applied in the XsltTransformer class. The patch will be available in the next maintenance release.
I have added a nunit test case to track for regression.
Please register to edit this issue