-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example-objectXML.html
60 lines (45 loc) · 1.06 KB
/
Example-objectXML.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta encoding="utf-8">
<title>XSLT</title>
</head>
<body>
<object id="xslt-object" type="text/xml" data="data/examplexsl.xml" width="800" height="300">
</object>
<pre>
<code id="output">
</code>
</pre>
<script type="text/javascript">
(function(){
function documentLoaded(){
if(!('XMLSerializer' in window)){
console.log('XSLTProcessor does not appear to be available in this browser. Please try another.');
return;
}
//object
serializeFromElement("xslt-object");
}
function serializeFromElement(value){
//get the object
const xsltobject = document.getElementById(value);
//get the output location
const output = document.getElementById("output");
//getting the document
const xsltDoc = xsltobject.contentDocument.documentElement;
//serialize the XML to a string
let s = new XMLSerializer();
let str = null;
try{
str = s.serializeToString(xsltDoc);
output.textContent = str;
}catch(error){
console.log(error);
}
}
window.addEventListener("load", documentLoaded, false);
}) ();
</script>
</body>
</html>