Skip to content

Instantly share code, notes, and snippets.

@themasch
Last active December 22, 2015 20:29
Show Gist options
  • Save themasch/6526880 to your computer and use it in GitHub Desktop.
Save themasch/6526880 to your computer and use it in GitHub Desktop.
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