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

发布于 2024-11-28 21:16:51 字数 925 浏览 5 评论 0原文

为什么我的 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" />

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

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

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

Why is my XHTML5 page causing IE's quirks mode?

Here is the doctype and such, including PHP which sends the MIME type and <?:

<?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" />

Then ie-xhtml-fix.xsl, from http://www.w3.org/MarkUp/2004/xhtml-faq#ie, is:

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

Sorry I have to ask. I can't seem to figure this out, I can't find any info about what could be causing the problem. I'm hoping for it to work in IE7 and up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2024-12-05 21:16:52

问题似乎是您的 XSLT 模板将处理指令复制到输出,这意味着 IE 在 doctype 之前解析它们,这会导致 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 及更高版本中测试并工作。

The problem appears to be that your XSLT template is copying the processing instructions to the output, which means that they are parsed by IE before the doctype, and this causes IE to go into Quirks mode.

Try this XSLT instead:

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

Tested and working in IE6 and above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文