-
Notifications
You must be signed in to change notification settings - Fork 53
/
games.xslt
180 lines (169 loc) · 5.28 KB
/
games.xslt
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Games">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
* {
box-sizing: border-box;
}
#myInput,#myInputDetail {
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable th {
cursor: pointer;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<p><a href="index.html">Back</a></p>
<p><xsl:value-of select="count(Game)"/> games listed.</p>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search in titles and developer names..." title="Enter a search term" />
<xsl:choose>
<xsl:when test="/Games/Game/Description">
<input type="text" id="myInputDetail" onkeyup="myFunction2()" placeholder="Search in descriptions..." title="Enter a search term" />
</xsl:when>
</xsl:choose>
<script>
<![CDATA[
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
id = tr[i].getAttribute("id");
if (id != "header") {
tds = tr[i].getElementsByTagName("td");
display = "none"
for (j = 0; j < tds.length; j++) {
td = tds[j]
if (td && (td.getAttribute("id") == "GameName" || td.getAttribute("id") == "Developer")) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
display = "";
break;
}
}
}
tr[i].style.display = display;
}
}
}
function myFunction2() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInputDetail");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
id = tr[i].getAttribute("id");
if (id != "header") {
title = tr[i].getAttribute("title");
if (!filter || (title && title.toUpperCase().indexOf(filter) > -1)) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
]]>
</script>
<table id="myTable" >
<tr bgcolor="#9acd32" id="header">
<xsl:choose>
<xsl:when test="/Games/Game/Region_Icon">
<th>Cover</th>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/Games/Game/@type">
<th>Type</th>
</xsl:when>
</xsl:choose>
<th>Title</th>
<th>Developer</th>
<xsl:choose>
<xsl:when test="/Games/Game/ImportedDate">
<th>Imported Date</th>
</xsl:when>
</xsl:choose>
</tr>
<xsl:for-each select="Game">
<xsl:sort select="GameName"/>
<xsl:element name="tr">
<xsl:choose>
<xsl:when test="Description != ''">
<xsl:attribute name="title"><xsl:value-of select="Description"/></xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:variable name="icon"><xsl:value-of select="substring-before(substring-after(Region_Icon,', '),']')"/></xsl:variable>
<xsl:choose>
<xsl:when test="/Games/Game/Region_Icon">
<td>
<xsl:choose>
<xsl:when test="Region_Icon!=''">
<img height="64" width="64" alt="icon" src="{$icon}" />
</xsl:when>
<xsl:otherwise>
<img height="64" width="64" alt="icon" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="/>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/Games/Game/@type">
<td><xsl:value-of select="@type"/></td>
</xsl:when>
</xsl:choose>
<td id="GameName"><xsl:value-of select="GameName"/></td>
<td id="Developer"><xsl:value-of select="Developer"/></td>
<td id="ImportedDate"><xsl:value-of select="ImportedDate"/></td>
</xsl:element>
</xsl:for-each>
</table>
</body>
<script>
<![CDATA[
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
// do the work...
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
const table = th.closest('table');
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
.forEach(tr => table.appendChild(tr) );
})));
]]>
</script>
</html>
</xsl:template>
</xsl:stylesheet>