//我完全将XML DOM作为源变量 以前我的页面只支持Internet Explorer,它绝对正常工作,但现在还需要支持firefox和chrome,以便进行必要的更改。
了解到transformNodeToObject只能与IE一起使用,而不能与其他浏览器一起使用。在diff博客中搜索了解需要导入XSL样式表并使用transformToDocument与firefox n chrome一起使用。添加了相同的内容可以在else块中看到,但是得到以下错误: -
组件返回失败代码:0x80600001 [nsIXSLTProcessor.importStylesheet] result.importStylesheet(sortPropertiesXSL);
<html>
<head>
<script>
var properties_xmlDoc = null;
function loadProperties()
{
var oXMLContainer = findObject("propertiesXML");
var sortPropertiesXSL = findObject("sortPropertiesXSL");
if (properties_xmlDoc == null)
{
properties_xmlDoc = loadXMLFromString(oXMLContainer.value);
}
//for IE
if(window.ActiveXObject){
properties_xmlDoc.transformNodeToObject(sortPropertiesXSL, properties_xmlDoc);
}
//for other browser
else {
var result = new XSLTProcessor();
result.importStylesheet(sortPropertiesXSL);
result = result.transformToDocument(properties_xmlDoc);
}
findObject("propValueDiv").innerHTML = findObject("propertyValueString").innerHTML;
}
function findObject(id) {
return document.getElementById(id);
}
</script>
</head>
<body onload="loadProperties()">
<div id="propValueDiv" />
<div id="propertyValueString" style="display:none">
<textarea name="propertyValue" id="propertyValue"</textarea>
</div>
</body>
</html>
这是我的xsl: -
<xml id="sortPropertiesXSL" style="display:none;">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8" cdata-section-elements="name description value"/>
<xsl:template match="properties">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort data-type="text" select="name"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</xml>
有人可以告诉我为什么ff会抛出这个问题以及如何解决这个问题。 感谢
答案 0 :(得分:0)
不要尝试在HTML文档中嵌入XML(XSLT)。旧的IE版本支持这一点,因为所谓的XML数据岛,但其他浏览器从未支持过,因此嵌入HTML中的XSLT代码在Firefox中解析为HTML而不是XML。将XSLT放在您自己使用XMLHttpRequest加载的文件中,这样就可以将其解析为XML。