我用xml和xslt 1.0编写了两个html页面。我希望将它们作为一个长html页面显示在彼此之后。我使用函数loadXMLDoc(filename)来转换我的xml和xsl。
第一页:http://www.halfmen.dk/2016/teams/fks.htm 第二页:http://www.halfmen.dk/2016/teams/fks-fixtures.htm
提前谢谢你。 McClaud
示例页面:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(filename) {
if (window.ActiveXObject) {
xhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
xhttp = new XMLHttpRequest();
}
xhttp.open("GET", filename, false);
try {
xhttp.responseType = "msxml-document"
} catch (err) {
}
xhttp.send("");
return xhttp.responseXML;
}
function displayResult() {
xml = loadXMLDoc("fixtures.xml");
xsl = loadXMLDoc("fks-fixtures.xsl");
if (window.ActiveXObject || xhttp.responseType == "msxml-document") {
ex = xml.transformNode(xsl);
document.getElementById("input").innerHTML = ex;
}
else if (document.implementation && document.implementation.createDocument) {
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml, document);
document.getElementById("input").appendChild(resultDocument);
}
}
</script>
</head>
<body class="animsition" onload="displayResult()">
<div id="input"></div>
</body>
</html>
答案 0 :(得分:0)
我强烈建议您切换到服务器端XSLT转换,而不是在客户端上进行繁重的工作。
尽管如此,你可以链接转换并简单地显示两个结果:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(filename) {
if (window.ActiveXObject) {
xhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
xhttp = new XMLHttpRequest();
}
xhttp.open("GET", filename, false);
try {
xhttp.responseType = "msxml-document"
} catch (err) {
}
xhttp.send("");
return xhttp.responseXML;
}
function displayResult() {
render('opponents.xml', 'fks.xsl');
render('fks.xml', 'fks-fixtures.xsl');
}
function render(xml, xsl) {
xml = loadXMLDoc(xml);
xsl = loadXMLDoc(xsl);
if (window.ActiveXObject || xhttp.responseType == "msxml-document") {
ex = xml.transformNode(xsl);
document.getElementById("input").innerHTML += ex;
}
else if (document.implementation && document.implementation.createDocument) {
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml, document);
document.getElementById("input").appendChild(resultDocument);
}
}
</script>
</head>
<body class="animsition" onload="displayResult();">
<div id="input"></div>
</body>
</html>