【发布时间】:2012-06-22 10:17:54
【问题描述】:
我在使用 Internet Explorer 9 和 Firefox 13 时遇到了一些问题。我正在使用 HTML、XSL 和 XML 构建一个 Web 界面,它在 Chrome、Opera 和 Safari 上运行良好,无需任何更改,但它不适用于Firefox 13 和 Internet Explorer 9。对于 Firefox,有些页面(不是全部)无法加载 XML 值,在 Internet Explorer 中,我无法为使用 XSLT 的 html 页面加载 css,但我可以加载所有参数正确。
您可以在上面找到一个不起作用的页面示例(HTML、XML、XSL)
HTML
<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname+"?id="+Math.random(),false);
xhttp.send("");
return xhttp.responseXML;
}
function displayResult()
{
xml=loadXMLDoc("sensorParameters.xml");
xsl=loadXMLDoc("sensorParameters.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("example").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
<head>
<meta http-equiv="cache-control" content="no-cache">
</head>
</html>
XSL
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<title>Interface</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
...
(It continues, but it is not important...)
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sensorParameters.xsl"?>
<section1>
<section2>
......... some data
</section2>
<section3>
......... some data
</section3>
.........
</section1>
任何帮助将不胜感激。
马可
【问题讨论】:
-
您能否将 URL 发布到一个最小但完整的示例,该示例在 Firefox 中失败,并更详细地解释失败的原因,例如如果出现错误,究竟是哪一个?
-
您可能想看看 Saxon-CE,它有望为您解决大部分跨浏览器兼容性问题。
-
@MartinHonnen 嗨,马丁,感谢您的回复。我无法发布 URL,因为我在本地工作。发生的情况是,如果我有一个表要填充 XML 文件中的一些值,Firefox 将无法加载它们。但是,如果我使用 firebug 查看页面的源代码,我会看到 firefox 正确加载了参数,但无法显示它们。
-
@MichaelKay 我去看看,谢谢
-
您的示例(甚至修改为测试 css)在 FF 中为我工作。我建议添加一个
<xsl:output method="html">。由于您在本地工作,FF 对允许来自不同基本 url 的片段也非常挑剔,因此请注意这一点。
标签: html firefox xslt google-chrome internet-explorer-9