XSLT fails to add DOCTYPE using xs:output
I'm using XSLT to create a HTML output page. I need to add a doctype to the output page. I googled and this seems to be able to get it working:
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>
So I added it to a test transformation file, transform.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>
<xsl:template match="/">
<html>
<head>
<title>test</title>
</head>
<body>
content!
</body>
</html>
</xsl:template>
</xsl:s开发者_开发百科tylesheet>
But the output HTML does not contain a doctype... . The rest of the example ... comes out fine.
What am I doing wrong, why isn't the doctype added?
Thanks!
EDIT: problem solved, I'm using eXist and it seems the xsl:output instruction will not work, the solution: mailing list
I can think of two possible answers
(a) your XSLT processor is not conformant with the spec, or
(b) your XSLT processor is not doing the serialization of the result tree, something else is. If the serialization is done by something other than the XSLT processor (e.g. if you send output to a DOM and then use the DOM serializer) then the XSLT serialization properties will be ignored.
精彩评论