-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrossBrowserXsltExample01.htm
More file actions
executable file
·44 lines (37 loc) · 1.66 KB
/
Copy pathCrossBrowserXsltExample01.htm
File metadata and controls
executable file
·44 lines (37 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<title>Cross-Browser XSLT Example</title>
<script type="text/javascript">
function transform(context, xslt){
if (typeof XSLTProcessor != "undefined"){
var processor = new XSLTProcessor();
processor.importStylesheet(xslt);
var result = processor.transformToDocument(context);
return (new XMLSerializer()).serializeToString(result);
} else if (typeof context.transformNode != "undefined") {
return context.transformNode(xslt);
} else {
throw new Error("No XSLT processor available.");
}
}
window.onload = function () {
//use XHR to load
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("get", "employees.xml", false);
xmlhttp.send(null);
var xmldom = xmlhttp.responseXML;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("get", "employees.xslt", false);
xmlhttp.send(null);
var xsltdom = xmlhttp.responseXML;
var result = transform(xmldom, xsltdom);
alert(result);
}
</script>
</head>
<body>
<p>This example will work in IE 7+ as well as Firefox 1.0+, Safari 3.0+, and Opera 9.0+. For IE, you may have to run this example on a server.</p>
<div id="divResult"></div>
</body>
</html>