Here I am explaining how to add xsl to xml using javascript.
<html>
<head>
<script type="text/javascript">
// code for IE
if (window.ActiveXObject)
{
var xmlDoc;
var xml1;
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("students.xml");
xml1=new ActiveXObject("Microsoft.XMLDOM");
xml1.async=false;
xml1.load("studentmarks.xsl");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var requester = new XMLHttpRequest();
var processor = new XSLTProcessor();
var serializer = new XMLSerializer();
var xml = getXMLDocument("students.xml");
var xsl1 = getXMLDocument("studentmarks.xsl");
processor.importStylesheet(xsl1);
var newXML = processor.transformToDocument(xml);
addXMLResult("Test", newXML);
}
else
{
alert('Your browser cannot handle this script');
}
function getXMLDocument(name)
{
requester.open("GET", name, false);
requester.send(null);
return requester.responseXML;
}
function addXMLResult(name, result)
{
var str;
if (result)
str = serializer.serializeToString(result);
document.writeln(str);
}
</script>
</head>
</html>
No comments:
Post a Comment