5

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

4

1 回答 1

1

我能想到两个可能的答案

(a) 您的 XSLT 处理器不符合规范,或者

(b) 您的 XSLT 处理器没有对结果树进行序列化,而是在进行其他操作。如果序列化不是由 XSLT 处理器完成的(例如,如果您将输出发送到 DOM,然后使用 DOM 序列化程序),那么 XSLT 序列化属性将被忽略。

于 2011-05-13T23:21:21.013 回答