-
Notifications
You must be signed in to change notification settings - Fork 17
/
to-html.xsl
418 lines (365 loc) · 10.4 KB
/
to-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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<?xml version="1.0" encoding="UTF-8"?>
<!--
Convert OccamDoc to HTML
Adam Sampson <ats@offog.org>
Copyright 2006 University of Kent, Canterbury, UK
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
-->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="html"
encoding="ISO-8859-1"
standalone="yes"
doctype-public="-//W3C//DTD HTML 4.01//EN"
doctype-system="http://www.w3.org/TR/html4/strict.dtd"
/>
<!-- Parameters -->
<xsl:param name="moduleid" select="''" />
<xsl:param name="mode" select="'page'" />
<!-- Keys -->
<xsl:key name="name" match="declaration" use="@name" />
<!-- The root of the output -->
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="/occamDoc">
<xsl:choose>
<xsl:when test="$mode='index' or $mode='frames-index'">
<xsl:apply-templates select="." mode="index" />
</xsl:when>
<xsl:when test="$mode='page'">
<xsl:apply-templates select="." mode="page" />
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="head">
<xsl:param name="title" />
<head>
<title><xsl:value-of select="$title" /></title>
<link rel="stylesheet" href="occamdoc.css" type="text/css" />
</head>
</xsl:template>
<xsl:template match="/occamDoc" mode="index">
<xsl:variable name="title">OccamDoc index</xsl:variable>
<html>
<xsl:call-template name="head">
<xsl:with-param name="title" select="$title" />
</xsl:call-template>
<body>
<xsl:if test="$mode='index'">
<h1><xsl:value-of select="$title" /></h1>
<p>
<a href="frames.html" target="_top">Show frames</a>
</p>
</xsl:if>
<xsl:if test="$mode='frames-index'">
<p>
<a href="index.html" target="page">Full index</a>
<br />
<a href="index.html" target="_top">Hide frames</a>
</p>
</xsl:if>
<div id="{$mode}">
<h2>Modules</h2>
<ul>
<xsl:apply-templates select="declaration" mode="index">
<xsl:sort order="ascending" select="@name" />
</xsl:apply-templates>
</ul>
<h2>Declarations</h2>
<ul>
<xsl:apply-templates select="declaration/children/declaration" mode="index">
<xsl:sort order="ascending" select="@name" />
</xsl:apply-templates>
</ul>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="/occamDoc" mode="page">
<xsl:variable name="decls" select="declaration[@name=$moduleid]" />
<html>
<xsl:call-template name="head">
<xsl:with-param name="title" select="$decls/summary" />
</xsl:call-template>
<body>
<div id="content">
<xsl:apply-templates select="$decls" />
</div>
</body>
</html>
</xsl:template>
<!-- OccamDoc for declarations -->
<xsl:template name="type-string">
<xsl:choose>
<xsl:when test="@type = 'module'">
<xsl:text>Module</xsl:text>
</xsl:when>
<xsl:when test="@type = 'proctype'">
<xsl:text>Process type</xsl:text>
</xsl:when>
<xsl:when test="@type = 'proc'">
<xsl:text>Process</xsl:text>
</xsl:when>
<xsl:when test="@type = 'function'">
<xsl:text>Function</xsl:text>
</xsl:when>
<xsl:when test="@type = 'operator'">
<xsl:text>Operator</xsl:text>
</xsl:when>
<xsl:when test="@type = 'record'">
<xsl:text>Record</xsl:text>
</xsl:when>
<xsl:when test="@type = 'chantype'">
<xsl:text>Channel type</xsl:text>
</xsl:when>
<xsl:when test="@type = 'protocol'">
<xsl:text>Protocol</xsl:text>
</xsl:when>
<xsl:when test="@type = 'datatype'">
<xsl:text>Data type</xsl:text>
</xsl:when>
<xsl:when test="@type = 'abbreviation'">
<xsl:text>Abbreviation</xsl:text>
</xsl:when>
<xsl:when test="@type = 'constant'">
<xsl:text>Constant</xsl:text>
</xsl:when>
<xsl:when test="@type = 'variable'">
<xsl:text>Variable</xsl:text>
</xsl:when>
<xsl:when test="@type = 'tag'">
<xsl:text>Tag</xsl:text>
</xsl:when>
<xsl:when test="@type = 'group'">
<xsl:text>Group</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Something else</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="decl-set">
<ul>
<xsl:for-each select="declaration">
<xsl:sort order="ascending" select="@name" />
<xsl:apply-templates select="." mode="index" />
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template match="declaration" mode="index">
<li>
<a class="{@type}">
<xsl:if test="$mode='frames-index'">
<xsl:attribute name="target">page</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="@type='module'">
<xsl:attribute name="href"><xsl:value-of select="@name" />.html</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href"><xsl:value-of select="ancestor::declaration[@type='module']/@name" />.html#name-<xsl:value-of select="@name" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$mode!='frames-index'">
<xsl:call-template name="type-string" />
<xsl:text> </xsl:text>
</xsl:if>
<xsl:call-template name="decl-name-list" />
</a>
<xsl:if test="summary and $mode!='frames-index'">
<xsl:text> - </xsl:text>
<xsl:value-of select="summary" />
</xsl:if>
<xsl:if test="children and @type!='module'">
<br />
<xsl:for-each select="children">
<xsl:call-template name="decl-set" />
</xsl:for-each>
</xsl:if>
</li>
</xsl:template>
<xsl:template name="decl-name-list">
<xsl:for-each select="name">
<code><xsl:value-of select="." /></code>
<xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="decl-param-items">
<tr>
<td class="param-type">
<code><xsl:apply-templates select="definition" /></code>
</td>
<xsl:choose>
<xsl:when test="item/@name">
<td class="param-name">
<xsl:for-each select="item">
<code><xsl:value-of select="@name" /></code>
<xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:for-each>
</td>
</xsl:when>
<xsl:otherwise>
<td class="param-name" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="description">
<td class="param-desc">
<xsl:apply-templates select="description" mode="inline" />
</td>
</xsl:if>
</tr>
</xsl:template>
<xsl:template name="decl-params">
<div class="description">
<xsl:apply-templates select="description" />
</div>
<xsl:if test="deprecated">
<p class="deprecated">
Deprecated: do not use in new code.
</p>
</xsl:if>
<xsl:if test="since">
<h4>Available since:</h4>
<div class="since">
<xsl:apply-templates select="since" />
</div>
</xsl:if>
<xsl:if test="params/description or items/description">
<h4>Parameters:</h4>
<div class="params">
<table>
<xsl:for-each select="params|items">
<xsl:call-template name="decl-param-items" />
</xsl:for-each>
</table>
</div>
</xsl:if>
<xsl:if test="returns/description">
<h4>Returns:</h4>
<div class="returns">
<table>
<xsl:for-each select="returns">
<xsl:call-template name="decl-param-items" />
</xsl:for-each>
</table>
</div>
</xsl:if>
<xsl:if test="maintainer">
<h4>Maintainer:</h4>
<div class="maintainer">
<xsl:apply-templates select="maintainer" />
</div>
</xsl:if>
</xsl:template>
<xsl:template match="declaration[@type='module']">
<div id="module-{@name}" class="module">
<h1>
<xsl:text>Module </xsl:text>
<code><xsl:value-of select="name" /></code>
<xsl:if test="summary">
<xsl:text> - </xsl:text>
<xsl:value-of select="summary" />
</xsl:if>
</h1>
<xsl:if test="description">
<div class="header">
<xsl:call-template name="decl-params" />
</div>
</xsl:if>
<h2>Index</h2>
<xsl:for-each select="children">
<xsl:call-template name="decl-set" />
</xsl:for-each>
<h2>Declarations</h2>
<xsl:apply-templates select="children" />
</div>
</xsl:template>
<xsl:template match="declaration">
<div id="name-{@name}" class="declaration {@type}">
<h3>
<xsl:if test="lineNumber">
<span class="location">
<code><xsl:value-of select="filename" /></code>
<xsl:text>:</xsl:text>
<xsl:value-of select="lineNumber" />
</span>
</xsl:if>
<xsl:call-template name="type-string" />
<xsl:text> </xsl:text>
<xsl:call-template name="decl-name-list" />
</h3>
<p class="definition">
<code><xsl:value-of select="definition" /></code>
</p>
<xsl:call-template name="decl-params" />
<xsl:if test="children">
<div class="children">
<xsl:apply-templates select="children" />
</div>
</xsl:if>
</div>
</xsl:template>
<!-- Free text -->
<xsl:template match="link">
<a href="{@href}">
<xsl:apply-templates />
</a>
</xsl:template>
<xsl:template match="ref">
<xsl:choose>
<xsl:when test="key('name',@href)/@type='module'">
<a href="{key('name',@href)/@name}.html">
<code><xsl:value-of select="key('name',@href)/name" /></code>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{key('name',@href)/ancestor::declaration[@type='module']/@name}.html#name-{key('name',@href)/@name}">
<code><xsl:value-of select="key('name',@href)/name" /></code>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="para">
<p><xsl:apply-templates /></p>
</xsl:template>
<xsl:template match="para" mode="inline">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="code">
<code><xsl:apply-templates /></code>
</xsl:template>
<xsl:template match="text">
<code><xsl:apply-templates /></code>
</xsl:template>
<!-- These two rules use the pre element to render paragraphs containing only
code blocks (and only whitespace in text elements). -->
<xsl:template match="para[normalize-space(.) = normalize-space(code)]">
<pre><code><xsl:value-of select="code" /></code></pre>
</xsl:template>
<xsl:template match="para[normalize-space(.) = normalize-space(text)]">
<pre><xsl:value-of select="text" /></pre>
</xsl:template>
<xsl:template match="em">
<em><xsl:apply-templates /></em>
</xsl:template>
<xsl:template match="list">
<ul><xsl:apply-templates /></ul>
</xsl:template>
<xsl:template match="listitem">
<li><xsl:apply-templates /></li>
</xsl:template>
</xsl:stylesheet>