XSL的浏览器行为 - 与IE / Chrome不同的Firefox

时间:2010-10-04 22:55:25

标签: internet-explorer firefox safari xslt

我有以下简单的XSL样式表:

<?xml version="1.0" encoding="windows-1252"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns="http://www.w3.org/1999/xhtml" version="1.0">
  <xsl:output encoding="utf-8" method="html" />

  <xsl:template match="/">

    <xsl:text disable-output-escaping="yes">
    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
      </xsl:text>
    <html>
      <head><title>hello world</title></head>
      <body>
        <p>hello world</p>
        </body>
      </html>
    </xsl:template>

  </xsl:stylesheet>

当我使用它时,Internet Explorer 7和Safari 5.0.2都只是按预期显示“hello world”。但是,Firefox 3.6.10显示了不同的内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

hello world

我猜测Firefox正在逐字地采用第一个xsl:text命令,而IE和Safari将它视为页面的一部分。 IE和Safari是否正确呈现了这个,或者是Firefox?

(我正在做xsl:text事情,使MSXML库输出正确的HTML5兼容标签。)

1 个答案:

答案 0 :(得分:1)

现代浏览器不需要输出标准模式渲染的DOCTYPE声明。只有IE有一些问题:它以标准模式呈现,但失去了CSS引擎的新功能(IE7回滚到IE6,例如)。

xsl:output声明是最好的工具,但是当使用PUBLIC和SYSTEM标识符进行输出声明时,某些Opera版本与fn:document有一些问题。我应该测试Opera 10.X的新行为,因为Opera 9.X的市场份额非常低。

唯一的解决方法是输出DOCTYPE声明(DOE文本),但仅适用于IE:您可以使用xsl:vendor函数测试system-property