【发布时间】:2015-01-15 08:30:03
【问题描述】:
// 我完美地将我的 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 抛出的,以及如何解决这个问题。 谢谢
【问题讨论】:
标签: javascript xml firefox xslt cross-browser