-
Notifications
You must be signed in to change notification settings - Fork 12
/
ProtocolDescription_xml2html.xsl
279 lines (234 loc) · 8.72 KB
/
ProtocolDescription_xml2html.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" media-type="text/html" encoding="utf-8"/>
<!--
See DTD file for more info on various elements/attributes!
Some useful links:
******************
How to test if node contains no text:
http://www.dpawson.co.uk/xsl/sect2/N3328.html#d4281e58
List of css tags:
http://www.w3.org/TR/REC-CSS1
CSS font-family:
http://www.codestyle.org/css/font-family/
-->
<xsl:template match="h3">
<h3><xsl:apply-templates/></h3>
</xsl:template>
<xsl:template match="h4">
<h4><xsl:apply-templates/></h4>
</xsl:template>
<xsl:template match="code">
<code><xsl:apply-templates/></code>
</xsl:template>
<xsl:template match="ProtocolDescription">
<html>
<head>
<title>Spring lobby protocol description</title>
<style type="text/css">
h3 {
color: navy;
font-size: 1.1em;
line-height: 1.25em;
text-align: left;
margin-top: 0;
margin-bottom: 0.25em;
border-bottom: 1px solid navy
}
h1 {color: navy;}
h2 {color: navy;}
h4 {color: navy;}
</style>
</head>
<body>
<h1>Spring lobby protocol description</h1>
<table border="0" style='width: 750px; table-layout: fixed; border: 2px dotted gray;'>
<tr><td>
<xsl:apply-templates select="Intro"/>
</td></tr>
</table>
<a name="Changelog"/> <!-- we need this to reference it with "a href" tag -->
<h2> Compatibility Flags </h2>
<table border="0" style='width: 750px; table-layout: fixed; border: 2px dotted gray;'>
<tr><td>
<xsl:apply-templates select="CompatFlags"/>
</td></tr>
</table>
<xsl:if test="./Versions">
<h2>Recent changes</h2>
<table border="0" style='width: 750px; table-layout: fixed; border: 2px dotted gray;'>
<xsl:for-each select="Versions/Version">
<tr><td>
<a name="{@Name}"/> <!-- we need this to reference it with "a href" tag -->
<h3>Version <xsl:value-of select="@Name"/></h3>
<xsl:if test="string(.)"><xsl:apply-templates select="." /></xsl:if>
</td></tr>
</xsl:for-each>
</table>
</xsl:if>
<h2>Command list</h2>
<xsl:for-each select="CommandList/Command">
<xsl:variable name="headercolor">
<xsl:choose>
<xsl:when test="@Source='client'">#9ACD32</xsl:when>
<xsl:otherwise>#E1EB72</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="commArgsList">
<xsl:for-each select="Arguments/Argument">
<xsl:choose>
<xsl:when test="@Optional='yes' and @Sentence='yes'"><xsl:text> </xsl:text>[{<xsl:value-of select="@Name"/>}]</xsl:when>
<xsl:when test="@Optional='no' and @Sentence='no'"><xsl:text> </xsl:text><xsl:value-of select="@Name"/></xsl:when>
<xsl:when test="@Optional='yes' and @Sentence='no'"><xsl:text> </xsl:text>[<xsl:value-of select="@Name"/>]</xsl:when>
<xsl:when test="@Optional='no' and @Sentence='yes'"><xsl:text> </xsl:text>{<xsl:value-of select="@Name"/>}</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<a name="{@Name}:{@Source}"/> <!-- we need this to reference it with "a href" tag -->
<table border="0" style='width: 750px; table-layout: fixed; border: 2px dotted gray;'>
<tr bgcolor="{$headercolor}">
<td style='color: #4E5152'>
<span style="font-weight: bold"><xsl:value-of select="@Name"/></span>
<span style="font-style: italic"><xsl:value-of select="$commArgsList"/></span>
</td>
<td style='width: 120px; text-align: center; font-style: italic'>
Source: <xsl:value-of select="@Source"/>
</td>
</tr>
<tr>
<td colspan="2">
<h3>Description</h3>
<xsl:apply-templates select="Description" />
<br />
<br />
<xsl:for-each select="Arguments/Argument">
<span style="color: #0066FF"><xsl:value-of select="@Name"/></span>
<xsl:if test="string(.)">: <xsl:apply-templates select="." /></xsl:if>
<br />
<br />
</xsl:for-each>
<xsl:if test="string(Response)">
<h3>Response</h3>
<xsl:apply-templates select="Response" />
<br />
<br />
</xsl:if>
<xsl:if test="Examples/*">
<h3>Examples</h3>
<xsl:for-each select="Examples/Example">
<xsl:if test="string(.)">
<xsl:apply-templates select="."/>
<br />
</xsl:if>
</xsl:for-each>
<br />
</xsl:if>
</td>
</tr>
</table>
<br />
</xsl:for-each>
<h2> Statistics </h2>
<table border="0" style='width: 750px; table-layout: fixed; border: 2px dotted gray;'>
<tr><td>
<p>
Some statistics on this document:<br />
<ul>
<li>Number of commands described: <xsl:value-of select="count(//Command)"/></li>
<li>Number of client commands: <xsl:value-of select="count(//Command[@Source='client'])"/></li>
<li>Number of server commands: <xsl:value-of select="count(//Command[@Source='server'])"/></li>
</ul>
</p>
</td></tr>
</table>
<br />
</body>
</html>
</xsl:template>
<!-- this overrides default built-in template for text nodes. Currently doesn't do anything useful! -->
<xsl:template match="text()">
<xsl:value-of select="(.)"/>
</xsl:template>
<xsl:template match="clink">
<xsl:variable name="type"><xsl:value-of select="substring-after(@name, ':')"/></xsl:variable> <!-- doesn't neccessarily exist! -->
<xsl:choose>
<xsl:when test="$type=''">
<!-- the ":x" post-fix doesn't exist -->
<xsl:choose>
<xsl:when test="//Command[@Name=current()/@name and @Source='client']">
<a href="#{@name}:client"><xsl:value-of select="@name"/></a>
</xsl:when>
<xsl:when test="//Command[@Name=current()/@name and @Source='server']">
<a href="#{@name}:server"><xsl:value-of select="@name"/></a>
</xsl:when>
<xsl:otherwise>
<!-- error: command does not exist! (link is broken) -->
<a href="#{@name}"><xsl:value-of select="@name"/></a><span style="color: red"> [broken link]</span>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- the ":x" post-fix exists -->
<xsl:choose>
<xsl:when test="starts-with($type,'c')">
<a href="#{substring-before(@name, ':')}:client"><xsl:value-of select="substring-before(@name, ':')"/></a>
</xsl:when>
<xsl:when test="starts-with($type,'s')">
<a href="#{substring-before(@name, ':')}:server"><xsl:value-of select="substring-before(@name, ':')"/></a>
</xsl:when>
<xsl:otherwise>
<!-- error: command does not exist! (link is broken) -->
<a href="#{@name}"><xsl:value-of select="@name"/></a><span style="color: red"> [broken link]</span>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="i">
<span style="font-style: italic;"><xsl:apply-templates /></span>
</xsl:template>
<xsl:template match="b">
<span style="font-weight: bold;"><xsl:apply-templates /></span>
</xsl:template>
<xsl:template match="u">
<span style="text-decoration: underline;"><xsl:apply-templates /></span>
</xsl:template>
<xsl:template match="br">
<br /><xsl:apply-templates />
</xsl:template>
<xsl:template match="br2">
<br /><br /><xsl:apply-templates />
</xsl:template>
<xsl:template match="p">
<p><xsl:apply-templates /></p>
</xsl:template>
<xsl:template match="ul">
<ul><xsl:apply-templates /></ul>
</xsl:template>
<xsl:template match="li">
<li><xsl:apply-templates /></li>
</xsl:template>
<xsl:template match="url">
<xsl:variable name="link"><xsl:value-of select="." /></xsl:variable>
<a href="{$link}" style="white-space: nowrap"><xsl:value-of select="$link" /></a>
</xsl:template>
<!-- This template replaces all newlines with html BR tags
Code has been copied from:
http://www.biglist.com/lists/xsl-list/archives/200310/msg01013.html
-->
<xsl:template name="insertBreaks">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '
')">
<xsl:value-of select="substring-before($text, '
')"/>
<br />
<xsl:call-template name="insertBreaks">
<xsl:with-param name="text" select="substring-after($text,'
')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>