Last active
December 22, 2015 20:29
-
-
Save themasch/6526880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xml = null, xsl = null; | |
function transformModern(type) { | |
return function() { | |
if(type == 'xml') { | |
xml = this.responseXML; | |
} else { | |
xsl = this.responseXML; | |
} | |
if(xml && xsl) { | |
var processor = new XSLTProcessor(); | |
processor.importStylesheet(stylesheet); | |
doc = processor.transformToDocument(xmlFile); | |
document.getElementById("data").innerHTML = doc.documentElement.innerHTML; | |
} | |
} | |
} | |
// separate transformation function for IE 6.0+ | |
function transformOld() { | |
var processor = cache.createProcessor(); | |
processor.input = xmlFile; | |
processor.transform(); | |
data.innerHTML = processor.output; | |
} | |
function load(file, cb) { | |
var xmlhttp = new window.XMLHttpRequest(); | |
xmlhttp.open("GET",file,false); | |
xmlhttp.addEventListener('load', cb, false); | |
xmlhttp.send(null); | |
} | |
if (window.ActiveXObject) { | |
xmlFile = new ActiveXObject("msxml2.DOMDocument.3.0"); | |
xmlFile.async = false; | |
xmlFile.load("site.xml"); | |
stylesheet = new ActiveXObject("msxml2.FreeThreadedDOMDocument.3.0"); | |
stylesheet.async = false; | |
stylesheet.load("web/site.xsl"); | |
cache = new ActiveXObject("msxml2.XSLTemplate.3.0"); | |
cache.stylesheet = stylesheet; | |
transformOld(); | |
} else { | |
load('site.xml', transformModern('xml')); | |
load('web/site.xsl', transformModern('xsl')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment