-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample-Include using script.html
106 lines (84 loc) · 4.72 KB
/
Example-Include using script.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="en">
<head>
<meta encoding="utf-8">
<title>XSLT</title>
</head>
<body>
<script id="xml" type="application/xml">
<extract>
<milestone n="1" unit="section"/>
<milestone unit="para"/>Thus the <name type="pers">Mermnadae</name> robbed the <name type="pers">Heraclidae</name> of the sovereignty and took it for themselves. Having gotten it, <name type="pers">Gyges</name> sent many offerings to <name key="perseus,Delphi" type="place" reg="Delphi [22.5167,38.4917] (Perseus) "><placeName key="perseus,Delphi" authname="perseus,Delphi">Delphi</placeName></name>: there are very many silver offerings of his there; and besides the silver, he dedicated a hoard of gold, among which six golden bowls are the offerings especially worthy of mention.
<milestone n="2" unit="section"/>These weigh thirty talents<note anchored="yes" resp="ed" place="unspecified">The “Attic” talent had a weight of about 58 lbs. avoirdupois, the “<name type="ethnic">Aeginetan</name>” of about 82.</note> and stand in the treasury<note anchored="yes" resp="ed" place="unspecified">Many <name type="ethnic">Greek</name> states had special “treasuries” allotted to them in the temple precincts at <name key="perseus,Delphi" type="place" reg="Delphi [22.5167,38.4917] (Perseus) "><placeName key="perseus,Delphi" authname="perseus,Delphi">Delphi</placeName></name>, in which their offerings were deposited.</note> of the <name type="ethnic">Corinthians</name>; although in truth it is not the treasury of the <name type="ethnic">Corinthian</name> people but of <name type="pers">Cypselus</name> son of <name type="pers">Eetion</name>. This <name type="pers">Gyges</name> then was the first foreigner whom we know who placed offerings at <name key="perseus,Delphi" type="place" reg="Delphi [22.5167,38.4917] (Perseus) "><placeName key="perseus,Delphi" authname="perseus,Delphi">Delphi</placeName></name> after the king of <name key="tgn,7002613" type="place" reg="Phrygia (region (general)), Turkey, Asia "><placeName key="tgn,7002613" authname="tgn,7002613">Phrygia</placeName></name>, <name type="pers">Midas</name> son of <name type="pers">Gordias</name>.
<milestone n="3" unit="section"/>For <name type="pers">Midas</name> too made an offering: namely, the royal seat on which he sat to give judgment, and a marvellous seat it is. It is set in the same place as the bowls of <name type="pers">Gyges</name>. This gold and the silver offered by <name type="pers">Gyges</name> is called by the <name type="ethnic">Delphians</name> “<name type="ethnic">Gygian</name>” after its dedicator.
</extract>
</script>
<script id="xslt" type="application/xml">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h1>Histories</h1>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="name">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
</xsl:stylesheet>
</script>
<div id="example"></div>
<script type="text/javascript">
//Run when document has loaded
(function(){
function documentLoaded(){
if(!('XSLTProcessor' in window && 'DOMParser' in window && 'XMLSerializer' in window)){
console.log('XSLTProcessor, DOMParser and XMLSerializer do not appear to be available in this browser. Please try another.');
return;
}
const xsltProcessor = new XSLTProcessor();
const parser = new DOMParser();
const serializer = new XMLSerializer();
//these need to be let since we will update values
let xsltDoc, xmlDoc, str = null;
//XSLT
const xslt = document.getElementById("xslt");
if(xslt){
xsltDoc = document.implementation.createDocument(null, "", null);
xsltDoc.appendChild(xslt);
console.log(xsltDoc);
const xsltStr = xsltDoc.documentElement.firstChild.textContent;
xsltcopyDoc = parser.parseFromString(xsltStr, "application/xml");
console.log(xsltcopyDoc);
const errorNode = xsltDoc.querySelector('parsererror');
if (errorNode) {
console.log(errorNode);
} else {
console.log("parsing ok");
}
}
//XSLT Processors and import XSLT
xsltProcessor.importStylesheet(xsltcopyDoc);
//XML
const xml = document.getElementById("xml");
if(xml){
xmlDoc = document.implementation.createDocument(null, "", null);
xmlDoc.appendChild(xml);
const xmlStr = xmlDoc.documentElement.firstChild.textContent;
xmlcopyDoc = parser.parseFromString(xmlStr, "application/xml");
console.log(xmlcopyDoc);
const errorNode = xmlDoc.querySelector('parsererror');
if (errorNode) {
console.log(errorNode);
} else {
console.log("parsing ok");
}
}
//now we can run the transformation and save to fragment
const fragment = xsltProcessor.transformToFragment(xmlcopyDoc, document);
document.getElementById("example").appendChild(fragment);
}
window.addEventListener("load", documentLoaded, false);
})();
</script>
</body>
</html>