js加载xml和xsl

html

<html>
<head >
<meta charset="utf-8" />
<script type="text/javascript">
window.onload = function () 
{
    //use XHR to load
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("get", "simple.xml", false);
    xmlhttp.send(null);
    var xmldom = xmlhttp.responseXML;

    xmlhttp = new XMLHttpRequest();
    xmlhttp.open("get", "simple.xsl", false);
    xmlhttp.send(null);
    var xsltdom = xmlhttp.responseXML;  

    var processor = new XSLTProcessor();
    processor.importStylesheet(xsltdom);

    var result = processor.transformToDocument(xmldom);
    var div = document.getElementById("divResult");

    var xml = (new XMLSerializer()).serializeToString(result);
    div.innerHTML = xml;

}
</script>
</head>
<div id="divResult"></div>
<body>
</body>
</html>

simple.xsl和simple.xml是对应的待加载的xml和xsl文件

上一篇:Unity3D笔记 GUI 二 、实现选项卡一窗口


下一篇:【Python学习笔记一】基础环境安装:idea+python