Saxon is right, the specifications are clear: when serializing the result document the doctype
declaration must be put immediately before the first element. This is specified in both XSLT 1.0 and XSLT 2.0:
If the doctype-system attribute is specified, the xml output method should output a document type declaration immediately before the first element.
To solve this you can add manually the doctype
declaration in your document, using the xsl:text
element with the disable-output-escaping
attribute set to yes
. For example you can output a standard HTML5 doctype, without any public identifier, which would be otherwise impossible to do in XSLT.
<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>