我是 XSLT 的新手,遇到了一些我不太理解的事情。我需要在转换文档之前添加一个 XSLT 参数。我可以像这样为非 IE 浏览器执行此操作:
function loadXMLDoc(dname) {
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET", dname, false);
xhttp.send("");
return xhttp.responseXML;
}
function displayResult() {
xml = loadXMLDoc("cdcatalog.xml");
xsl = loadXMLDoc("cdcatalog.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);
}
}
现在,我可以为非 IE 浏览器做这件事,创建一个新的 XSLT 处理器对象,导入样式表,您只需在转换过程之前添加参数。不过,对于 IE 版本的代码,这一切似乎都没有发生,而且我不能简单地在转换之前添加参数。我大量搜索并看到不同的东西告诉我创建各种不同 MSXML 版本的新 ActiveX 对象,我对整个事件深感困惑。
采用上面的代码,我该怎么做:
xsltProcessor.setParameter(null,"PARAMNAME","PARAMVALUE");
除了 IE,如果可能的话,有人可以解释 IE 如何以不同于 FF/O/C/其他文明浏览器的方式处理 XSLT 的整个概念吗?
最佳答案
您可以尝试使用 Sarissa,这是一个提供跨浏览器 XSLT 转换 API 的抽象层。
关于javascript - 如何使用 XSLT 转换 XML 文档并在 IE 中添加参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5533923/