其他分享
首页 > 其他分享> > js加载xml和xsl

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文件

标签:xml,xmlhttp,simple,js,var,new,xsl
来源: https://blog.csdn.net/JS_CSDN7510/article/details/120156991