Created
March 6, 2017 11:41
-
-
Save artemkonenko/0ef21a7d4cc66d89f127b0705a3b1b77 to your computer and use it in GitHub Desktop.
Routine for getting xml file, transforming it by xsl file and putting the result to select
This file contains 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
function loadXMLDoc(filename) | |
{ | |
if (window.ActiveXObject) | |
{ | |
xhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
} | |
else | |
{ | |
xhttp = new XMLHttpRequest(); | |
} | |
xhttp.open("GET", filename, false); | |
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11 | |
xhttp.send(""); | |
return xhttp.responseXML; | |
} | |
function buildXML(xmlPath, xslPath) | |
{ | |
const xml = loadXMLDoc(xmlPath); | |
const xsl = loadXMLDoc(xslPath); | |
// code for IE | |
if (window.ActiveXObject || xhttp.responseType == "msxml-document") | |
{ | |
ex = xml.transformNode(xsl); | |
return ex; | |
} | |
// code for Chrome, Firefox, Opera, etc. | |
else if (document.implementation && document.implementation.createDocument) | |
{ | |
xsltProcessor = new XSLTProcessor(); | |
xsltProcessor.importStylesheet(xsl); | |
resultDocument = xsltProcessor.transformToFragment(xml, document); | |
return resultDocument; | |
} | |
} | |
$(document).ready(function(){ | |
$('.selectpicker').selectpicker({ | |
style: 'btn-info' | |
// size: 4 | |
}); | |
const list = buildXML('/xslt/list.xml', '/xslt/discipline_selector_options.xsl'); | |
console.log(list); | |
$('.selectpicker').html(list); | |
$('.selectpicker').selectpicker('refresh'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment