非常簡單的代碼,我只是無法讓它工作。 XSLT中的參數始終爲空。我錯過了什麼?我正在使用FF6。請幫助,你的傢伙尖銳的眼睛。謝謝!
XSLT沒有從javascript傳遞參數
的index.html
<html>
<head>
<script>
function loadXMLDoc(dname) {
xhttp = new XMLHttpRequest();
xhttp.open("GET", dname, false);
xhttp.send("");
return xhttp.responseXML;
}
function displayResult(source,styledoc,section) {
xml = loadXMLDoc(source);
xsl = loadXMLDoc(styledoc);
if (window.ActiveXObject) {
ex = xml.transformNode(xsl);
document.getElementById("display").innerHTML = ex;
}
else if (document.implementation && document.implementation.createDocument) {
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
xsltProcessor.setParameter(null,"section",section);
alert(xsltProcessor.getParameter(null,"section"));
resultDocument = xsltProcessor.transformToFragment(xml, document);
document.getElementById("display").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult('test.xml','test.xslt','somevalue')">
<div id="display"/>
</body>
</html>
test.xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:param name="section"/>
section=<xsl:value-of select="$section"/>
</xsl:template>
</xsl:stylesheet>
的test.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<test/>
和你在腳本的firdt部分傳遞參數的地方? (IE版) – SergeS