简单教程
提交运行
代码编辑器:
<body> <div id="showcode"></div> </body> <script> var xmlhttp; function loadXmlFile(xmlFile){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() } else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") } else { return null; } xmlhttp.open("GET", xmlFile, false); xmlhttp.send(null); return xmlhttp.responseXML; } // Load XML var xml = loadXmlFile("/static/exam/xmle/cd_catalog.xml") // load XSL var xsl = loadXmlFile("/static/exam/xmle/cd_catalog.xsl") if (window.ActiveXObject || xmlhttp.responseType == "msxml-document") { rs = xml.transformNode(xsl); document.getElementById("showcode").innerHTML = rs; } // code for Chrome, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml, document); document.getElementById("showcode").appendChild(resultDocument); } </script>
运行结果: