Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:stylesheet>

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

like image 689
r1234x Avatar asked Nov 13 '22 23:11

r1234x


1 Answers

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.

like image 178
Michael Kay Avatar answered Dec 09 '22 20:12

Michael Kay