-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameSave-HTML.xsl
176 lines (159 loc) · 7.17 KB
/
gameSave-HTML.xsl
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:g="http://www.vse.cz/4iz238/sem/kuba10/XML/gameSave"
exclude-result-prefixes="xs g"
version="2.0">
<xsl:output method="html" version="5"/>
<!-- Default background is greyish, to change it use hex, rgb or name of color as this parametr -->
<xsl:param name="background" select="'#F5F5F5'"/>
<xsl:variable name="header">
<header>
<h1>Game save</h1>
<nav>
<a href="gameSave.html">Main page</a>
</nav>
</header>
</xsl:variable>
<!-- BASE -->
<xsl:template match="/">
<html lang="en">
<head>
<title>Game Save</title>
<link rel="stylesheet" href="../style.css" type="text/css"/>
</head>
<body style="background-color: {$background};">
<xsl:copy-of select="$header" />
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- MAIN PAGE -->
<xsl:template match="g:game">
<h2>Basic information</h2>
<h3>Map: <xsl:value-of select="./g:map"/></h3>
<img src="../imgs/{./g:map}.webp"/>
<h3>Player on turn: <xsl:apply-templates select="./g:playerOnTurn" mode="name"/></h3>
<div>
<h3>Player information</h3>
<xsl:apply-templates select="g:players" mode="menu"/>
</div>
<xsl:apply-templates select="./g:players/g:player" mode="pages"/>
</xsl:template>
<!-- PLAYER PAGES -->
<xsl:template match="g:player" mode="pages">
<xsl:result-document href="{generate-id(.)}.html">
<html lang="en">
<head>
<title><xsl:value-of select="g:name"/></title>
<link rel="stylesheet" href="../style.css" type="text/css"/>
</head>
<body style="background-color: {$background};">
<xsl:copy-of select="$header" />
<h2><xsl:value-of select="g:name"/></h2>
<h3>Commodities:</h3>
<xsl:apply-templates select="g:commodities" mode="displayAll"/>
<h3>Units</h3>
<xsl:apply-templates select="g:units" mode="displayAll"/>
<h3>Buildings</h3>
<xsl:apply-templates select="g:buildings" mode="displayAll"/>
</body>
</html>
</xsl:result-document>
</xsl:template>
<!-- _________________SMALL TEMPLATES________________ -->
<xsl:template match="g:playerOnTurn" mode="name">
<xsl:value-of select="./g:name"/>
</xsl:template>
<xsl:template match="g:players" mode="menu">
<xsl:for-each select="g:player">
<xsl:sort lang="en" select="g:name"/>
<a href="{generate-id(.)}.html"><xsl:value-of select="g:name"/></a>
<br/>
</xsl:for-each>
</xsl:template>
<xsl:template match="g:commodities" mode="displayAll">
<xsl:for-each select="g:commodity">
<p><span style="font-weight: bold;"><xsl:value-of select="@form"/></span> : <xsl:value-of select="@amount"/></p>
</xsl:for-each>
</xsl:template>
<xsl:template match="g:units" mode="displayAll">
<table>
<tr style="font-size: 120%; margin-bottom: 10px; margin-top: 10px;">
<th>Unit</th>
<th>Name</th>
<th>HP</th>
<th>Action reach</th>
<th>Damage</th>
<th>Position</th>
<th>Action Queue</th>
</tr>
<xsl:for-each select="g:unit">
<tr>
<th><img src="../imgs/{@category}.webp" alt="unit"></img></th>
<th><xsl:value-of select="@category"/></th>
<th><xsl:value-of select="g:hp"/></th>
<th><xsl:value-of select="g:actionReach"/></th>
<th><xsl:value-of select="g:damage"/></th>
<th>x = <xsl:value-of select="g:position/@x"/>, y = <xsl:value-of select="g:position/@y"/></th>
<th><xsl:apply-templates select="g:actionQueue" mode="unitDisplayAll"/></th>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="g:buildings" mode="displayAll">
<table>
<tr style="font-size: 120%; margin-bottom: 10px; margin-top: 10px;">
<th>Unit</th>
<th>Name</th>
<th>HP</th>
<th>Position</th>
<th>Action Queue</th>
</tr>
<xsl:for-each select="g:building">
<tr>
<th><img src="../imgs/{@category}.webp" alt="building"></img></th>
<th><xsl:value-of select="@category"/></th>
<th><xsl:value-of select="g:hp"/></th>
<th>x = <xsl:value-of select="g:position/@x"/>, y = <xsl:value-of select="g:position/@y"/></th>
<th><xsl:apply-templates select="g:actionQueue" mode="buildingDisplayAll"/></th>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="g:actionQueue" mode="unitDisplayAll">
<xsl:for-each select="g:action">
<xsl:value-of select="position()" /><xsl:text>. </xsl:text>
<xsl:choose>
<xsl:when test="@type = 'move'">
<xsl:text>Moving to x = </xsl:text> <xsl:value-of select="g:position/@x"/> <xsl:text> y = </xsl:text> <xsl:value-of select="g:position/@y"/>
</xsl:when>
<xsl:when test="@type = 'mine'"><xsl:text>Mining</xsl:text></xsl:when>
<xsl:when test="@type = 'attack'"><xsl:text>Attacking</xsl:text></xsl:when>
</xsl:choose>
<xsl:if test="@repeat = 'true'">, repeating this action</xsl:if>
<xsl:text>, turns to complete </xsl:text> <xsl:value-of select="g:turnsToComplete"/>
<br/>
</xsl:for-each>
</xsl:template>
<xsl:template match="g:actionQueue" mode="buildingDisplayAll">
<xsl:for-each select="g:action">
<xsl:value-of select="position()" /><xsl:text>. </xsl:text>
<xsl:choose>
<xsl:when test="@type = 'produce'">
<xsl:text>Producing </xsl:text>
<xsl:value-of select="g:commodity/@amount"/>
<xsl:text> of </xsl:text>
<xsl:value-of select="g:commodity/@form"/>
</xsl:when>
<xsl:when test="@type = 'spawn'">
<xsl:text>Spawning a </xsl:text>
<xsl:value-of select="g:unit/@category"/>
</xsl:when>
</xsl:choose>
<xsl:if test="@repeat = 'true'">, repeating this action</xsl:if>
<xsl:text>, turns to complete </xsl:text> <xsl:value-of select="g:turnsToComplete"/>
<br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>