You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IE浏览器关联XSL样式表后XML文件显示空白无内容问题求助

问题根源排查

    1. XPath字段拼写错误:XSL文件中引用最高温度字段时写的是higheset,但XML内对应节点名是highest,多写了一个字母e。IE浏览器对XSLT转换过程中的XPath匹配错误容错率极低,一旦出现无效字段引用就会直接终止渲染,返回空白页面且不会抛出可见报错。
    1. 属性匹配语法错误:queryLocation和queryTime都是forecast节点的属性,你原来的写法<xsl:value-of select="queryLocation"/>没有加@前缀,无法正确匹配属性值,也会触发转换异常。
    1. 输出格式适配问题:你当前设置<xsl:output method="xml" />,IE对XML格式输出的XHTML解析逻辑存在兼容缺陷,很容易出现解析失败的情况。
    1. 默认命名空间兼容风险:XSL根节点声明的xmlns="http://www.w3.org/1999/xhtml"默认命名空间,在低版本IE中也可能触发渲染异常。

修复后的XSL完整代码

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="html" indent="yes" encoding="UTF-8"/>
    
    <xsl:template match="/forecast">
        <html>
            <head>
                <title>Part 3</title>
            </head>
            <body>
                <h1><xsl:value-of select="@queryLocation"/>  [<xsl:value-of select="@queryTime"/>]</h1>
                <ul>
                  <xsl:for-each select="weather">
                    <li>
                      <xsl:value-of select="year" /> 
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="month" />
                      <xsl:text>, </xsl:text>
                      <xsl:value-of select="date" />
                      <xsl:text>, </xsl:text> 
                      <xsl:value-of select="dayOfWeek" />
                      <xsl:text>, </xsl:text> 
                      <xsl:value-of select="overall" />
                      <xsl:text>, </xsl:text> 
                      <xsl:value-of select="overallCode" />
                      <xsl:text>, </xsl:text> 
                      <xsl:value-of select="highest" />
                      <xsl:text>, </xsl:text> 
                      <xsl:value-of select="lowest" />
                    </li>
                  </xsl:for-each>
                </ul>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

验证操作说明

  1. 确认XML和XSL文件存放在同一目录,保证href="part3.xsl"路径配置正确
  2. 清除IE浏览器缓存后重新加载XML文件,IE对静态资源的缓存机制可能导致修改后的XSL文件不生效
  3. 若仍有异常,可按F12打开IE开发者工具,切换至兼容模式测试低版本IE的渲染效果

内容的提问来源于stack exchange,提问作者Geminianer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 22:24:03