1

为什么我的 XHTML5 页面会导致 IE 的怪癖模式?

这是文档类型等,包括发送 MIME 类型的 PHP 和<?

<?php header('Content-Type: application/xml;charset=UTF-8'); ?>
<?php echo '<?';?>xml version="1.0" encoding="UTF-8"?>
<?php echo '<?';?>xml-stylesheet type="text/xsl" href="ie-xhtml-fix.xsl"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr">
<head><meta charset="UTF-8" />

然后来自http://www.w3.org/MarkUp/2004/xhtml-faq#ie的 ie-xhtml-fix.xsl是:

<stylesheet version="1.0"
     xmlns="http://www.w3.org/1999/XSL/Transform">
    <template match="/">
        <copy-of select="."/>
    </template>
</stylesheet>

对不起,我不得不问。我似乎无法弄清楚这一点,我找不到任何有关可能导致问题的信息。我希望它可以在 IE7 及更高版本中运行。

4

1 回答 1

2

问题似乎是您的 XSLT 模板正在将处理指令复制到输出,这意味着它们在文档类型之前由 IE 解析,这导致 IE 进入 Quirks 模式。

试试这个 XSLT:

<stylesheet version="1.0"
     xmlns="http://www.w3.org/1999/XSL/Transform">
    <output method="html" version="1.0" encoding="UTF-8" doctype-system="about:legacy-compat" />

    <!-- Copy all the child nodes of the root -->
    <template match="/"> 
        <copy>
           <apply-templates select="node()|@*"/>
         </copy>
    </template>

    <!-- For any other node, just copy everything -->
    <template match="node()|@*"> 
       <copy-of select="."/>
    </template>

    <!-- For processing instructions directly under the root, discard -->
    <template match="/processing-instruction()" />
</stylesheet>

在 IE6 及更高版本中测试和工作。

于 2011-08-08T23:57:45.567 回答