【发布时间】:2011-04-04 02:08:59
【问题描述】:
我是学习 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 版本的代码,这似乎都没有发生,我不能简单地在转换之前添加参数。我在 Google 上大肆搜索,看到不同的东西告诉我要创建各种不同 MSXML 版本的新 ActiveX 对象,我对整个事件深感困惑。
使用上面的代码,我该怎么做:xsltProcessor.setParameter(null,"PARAMNAME","PARAMVALUE");
除了 IE,如果可能的话,谁能解释一下 IE 如何以与 FF/O/C/其他文明浏览器不同的方式处理 XSLT 的整个概念?
【问题讨论】:
标签: javascript xml xslt