Debian Codegraph @

doc/docbook-xsl/html/glossary.xsl

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY % common.entities SYSTEM "../common/entities.ent">
4 %common.entities;
5 ]>
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 version='1.0'>
8
9 <!-- ********************************************************************
10 $Id$
11 ********************************************************************
12
13 This file is part of the XSL DocBook Stylesheet distribution.
14 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
15 and other information.
16
17 ******************************************************************** -->
18
19 <!-- ==================================================================== -->
20
21 <xsl:variable name="language">
22 <xsl:call-template name="l10n.language"/>
23 </xsl:variable>
24
25 <xsl:template match="glossary">
26 <xsl:call-template name="id.warning"/>
27
28 <div>
29 <xsl:apply-templates select="." mode="class.attribute"/>
30 <xsl:if test="$generate.id.attributes != 0">
31 <xsl:attribute name="id">
32 <xsl:call-template name="object.id"/>
33 </xsl:attribute>
34 </xsl:if>
35
36 <xsl:call-template name="glossary.titlepage"/>
37
38 <xsl:choose>
39 <xsl:when test="glossdiv">
40 <xsl:apply-templates select="(glossdiv[1]/preceding-sibling::*)"/>
41 </xsl:when>
42 <xsl:otherwise>
43 <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
44 </xsl:otherwise>
45 </xsl:choose>
46
47 <xsl:choose>
48 <xsl:when test="glossdiv">
49 <xsl:apply-templates select="glossdiv"/>
50 </xsl:when>
51 <xsl:otherwise>
52 <dl>
53 <xsl:choose>
54 <xsl:when test="$glossary.sort != 0">
55 <xsl:apply-templates select="glossentry">
56 <xsl:sort lang="{$language}"
57 select="translate(glossterm, &lowercase;,
58 &uppercase;)"/>
59 </xsl:apply-templates>
60 </xsl:when>
61 <xsl:otherwise>
62 <xsl:apply-templates select="glossentry"/>
63 </xsl:otherwise>
64 </xsl:choose>
65 </dl>
66 </xsl:otherwise>
67 </xsl:choose>
68
69 <xsl:if test="not(parent::article)">
70 <xsl:call-template name="process.footnotes"/>
71 </xsl:if>
72 </div>
73 </xsl:template>
74
75 <xsl:template match="glossary/glossaryinfo"></xsl:template>
76 <xsl:template match="glossary/info"></xsl:template>
77 <xsl:template match="glossary/title"></xsl:template>
78 <xsl:template match="glossary/subtitle"></xsl:template>
79 <xsl:template match="glossary/titleabbrev"></xsl:template>
80
81 <!-- ==================================================================== -->
82
83 <xsl:template match="glosslist">
84 <div>
85 <xsl:apply-templates select="." mode="class.attribute"/>
86 <xsl:call-template name="anchor"/>
87 <xsl:if test="blockinfo/title|info/title|title">
88 <xsl:call-template name="formal.object.heading"/>
89 </xsl:if>
90 <dl>
91 <xsl:choose>
92 <xsl:when test="$glossary.sort != 0">
93 <xsl:apply-templates select="glossentry">
94 <xsl:sort lang="{$language}"
95 select="translate(glossterm, &lowercase;,
96 &uppercase;)"/>
97 </xsl:apply-templates>
98 </xsl:when>
99 <xsl:otherwise>
100 <xsl:apply-templates select="glossentry"/>
101 </xsl:otherwise>
102 </xsl:choose>
103 </dl>
104 </div>
105 </xsl:template>
106
107 <!-- ==================================================================== -->
108
109 <xsl:template match="glossdiv">
110 <xsl:call-template name="id.warning"/>
111
112 <div>
113 <xsl:apply-templates select="." mode="class.attribute"/>
114 <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
115
116 <dl>
117 <xsl:choose>
118 <xsl:when test="$glossary.sort != 0">
119 <xsl:apply-templates select="glossentry">
120 <xsl:sort lang="{$language}"
121 select="translate(glossterm, &lowercase;,
122 &uppercase;)"/>
123 </xsl:apply-templates>
124 </xsl:when>
125 <xsl:otherwise>
126 <xsl:apply-templates select="glossentry"/>
127 </xsl:otherwise>
128 </xsl:choose>
129 </dl>
130 </div>
131 </xsl:template>
132
133 <xsl:template match="glossdiv/title">
134 <h3>
135 <xsl:apply-templates select="." mode="class.attribute"/>
136 <xsl:apply-templates/>
137 </h3>
138 </xsl:template>
139
140 <!-- ==================================================================== -->
141
142 <!--
143 GlossEntry ::=
144 GlossTerm, Acronym?, Abbrev?,
145 (IndexTerm)*,
146 RevHistory?,
147 (GlossSee | GlossDef+)
148 -->
149
150 <xsl:template match="glossentry">
151 <xsl:choose>
152 <xsl:when test="$glossentry.show.acronym = 'primary'">
153 <dt>
154 <xsl:call-template name="anchor">
155 <xsl:with-param name="conditional">
156 <xsl:choose>
157 <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
158 <xsl:otherwise>1</xsl:otherwise>
159 </xsl:choose>
160 </xsl:with-param>
161 </xsl:call-template>
162
163 <xsl:choose>
164 <xsl:when test="acronym|abbrev">
165 <xsl:apply-templates select="acronym|abbrev"/>
166 <xsl:text> (</xsl:text>
167 <xsl:apply-templates select="glossterm"/>
168 <xsl:text>)</xsl:text>
169 </xsl:when>
170 <xsl:otherwise>
171 <xsl:apply-templates select="glossterm"/>
172 </xsl:otherwise>
173 </xsl:choose>
174 </dt>
175 </xsl:when>
176 <xsl:when test="$glossentry.show.acronym = 'yes'">
177 <dt>
178 <xsl:call-template name="anchor">
179 <xsl:with-param name="conditional">
180 <xsl:choose>
181 <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
182 <xsl:otherwise>1</xsl:otherwise>
183 </xsl:choose>
184 </xsl:with-param>
185 </xsl:call-template>
186
187 <xsl:apply-templates select="glossterm"/>
188
189 <xsl:if test="acronym|abbrev">
190 <xsl:text> (</xsl:text>
191 <xsl:apply-templates select="acronym|abbrev"/>
192 <xsl:text>)</xsl:text>
193 </xsl:if>
194 </dt>
195 </xsl:when>
196 <xsl:otherwise>
197 <dt>
198 <xsl:call-template name="anchor">
199 <xsl:with-param name="conditional">
200 <xsl:choose>
201 <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
202 <xsl:otherwise>1</xsl:otherwise>
203 </xsl:choose>
204 </xsl:with-param>
205 </xsl:call-template>
206
207 <xsl:apply-templates select="glossterm"/>
208 </dt>
209 </xsl:otherwise>
210 </xsl:choose>
211
212 <xsl:apply-templates select="indexterm|revhistory|glosssee|glossdef"/>
213 </xsl:template>
214
215 <xsl:template match="glossentry/glossterm">
216 <xsl:apply-templates/>
217 <xsl:if test="following-sibling::glossterm">, </xsl:if>
218 </xsl:template>
219
220 <xsl:template match="glossentry/acronym">
221 <xsl:apply-templates/>
222 <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
223 </xsl:template>
224
225 <xsl:template match="glossentry/abbrev">
226 <xsl:apply-templates/>
227 <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
228 </xsl:template>
229
230 <xsl:template match="glossentry/revhistory">
231 </xsl:template>
232
233 <xsl:template match="glossentry/glosssee">
234 <xsl:variable name="otherterm" select="@otherterm"/>
235 <xsl:variable name="targets" select="key('id', $otherterm)"/>
236 <xsl:variable name="target" select="$targets[1]"/>
237
238 <dd>
239 <p>
240 <xsl:variable name="template">
241 <xsl:call-template name="gentext.template">
242 <xsl:with-param name="context" select="'glossary'"/>
243 <xsl:with-param name="name" select="'see'"/>
244 </xsl:call-template>
245 </xsl:variable>
246
247 <xsl:variable name="title">
248 <xsl:choose>
249 <xsl:when test="$target">
250 <a>
251 <xsl:apply-templates select="." mode="class.attribute"/>
252 <xsl:attribute name="href">
253 <xsl:call-template name="href.target">
254 <xsl:with-param name="object" select="$target"/>
255 </xsl:call-template>
256 </xsl:attribute>
257 <xsl:apply-templates select="$target" mode="xref-to"/>
258 </a>
259 </xsl:when>
260 <xsl:when test="$otherterm != '' and not($target)">
261 <xsl:message>
262 <xsl:text>Warning: glosssee @otherterm reference not found: </xsl:text>
263 <xsl:value-of select="$otherterm"/>
264 </xsl:message>
265 <xsl:apply-templates/>
266 </xsl:when>
267 <xsl:otherwise>
268 <xsl:apply-templates/>
269 </xsl:otherwise>
270 </xsl:choose>
271 </xsl:variable>
272
273 <xsl:call-template name="substitute-markup">
274 <xsl:with-param name="template" select="$template"/>
275 <xsl:with-param name="title" select="$title"/>
276 </xsl:call-template>
277 <xsl:text>.</xsl:text>
278 </p>
279 </dd>
280 </xsl:template>
281
282 <xsl:template match="glossentry/glossdef">
283 <dd>
284 <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"/>
285 <xsl:if test="glossseealso">
286 <p>
287 <xsl:variable name="template">
288 <xsl:call-template name="gentext.template">
289 <xsl:with-param name="context" select="'glossary'"/>
290 <xsl:with-param name="name" select="'seealso'"/>
291 </xsl:call-template>
292 </xsl:variable>
293 <xsl:variable name="title">
294 <xsl:apply-templates select="glossseealso"/>
295 </xsl:variable>
296 <xsl:call-template name="substitute-markup">
297 <xsl:with-param name="template" select="$template"/>
298 <xsl:with-param name="title" select="$title"/>
299 </xsl:call-template>
300 </p>
301 </xsl:if>
302 </dd>
303 </xsl:template>
304
305 <xsl:template match="glossseealso">
306 <xsl:variable name="otherterm" select="@otherterm"/>
307 <xsl:variable name="targets" select="key('id', $otherterm)"/>
308 <xsl:variable name="target" select="$targets[1]"/>
309
310 <xsl:choose>
311 <xsl:when test="$target">
312 <a>
313 <xsl:apply-templates select="." mode="class.attribute"/>
314 <xsl:attribute name="href">
315 <xsl:call-template name="href.target">
316 <xsl:with-param name="object" select="$target"/>
317 </xsl:call-template>
318 </xsl:attribute>
319 <xsl:apply-templates select="$target" mode="xref-to"/>
320 </a>
321 </xsl:when>
322 <xsl:when test="$otherterm != '' and not($target)">
323 <xsl:message>
324 <xsl:text>Warning: glossseealso @otherterm reference not found: </xsl:text>
325 <xsl:value-of select="$otherterm"/>
326 </xsl:message>
327 <xsl:apply-templates/>
328 </xsl:when>
329 <xsl:otherwise>
330 <xsl:apply-templates/>
331 </xsl:otherwise>
332 </xsl:choose>
333
334 <xsl:choose>
335 <xsl:when test="position() = last()">
336 <xsl:text>.</xsl:text>
337 </xsl:when>
338 <xsl:otherwise>
339 <xsl:text>, </xsl:text>
340 </xsl:otherwise>
341 </xsl:choose>
342 </xsl:template>
343
344 <!-- ==================================================================== -->
345
346 <!-- Glossary collection -->
347
348 <xsl:template match="glossary[@role='auto']" priority="2">
349 <xsl:variable name="terms"
350 select="//glossterm[not(parent::glossdef)]|//firstterm"/>
351 <xsl:variable name="collection" select="document($glossary.collection, .)"/>
352
353 <xsl:call-template name="id.warning"/>
354
355 <xsl:if test="$glossary.collection = ''">
356 <xsl:message>
357 <xsl:text>Warning: processing automatic glossary </xsl:text>
358 <xsl:text>without a glossary.collection file.</xsl:text>
359 </xsl:message>
360 </xsl:if>
361
362 <xsl:if test="not($collection) and $glossary.collection != ''">
363 <xsl:message>
364 <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
365 <xsl:text>open glossary.collection file '</xsl:text>
366 <xsl:value-of select="$glossary.collection"/>
367 <xsl:text>'</xsl:text>
368 </xsl:message>
369 </xsl:if>
370
371 <div>
372 <xsl:apply-templates select="." mode="class.attribute"/>
373 <xsl:if test="$generate.id.attributes != 0">
374 <xsl:attribute name="id">
375 <xsl:call-template name="object.id"/>
376 </xsl:attribute>
377 </xsl:if>
378
379 <xsl:call-template name="glossary.titlepage"/>
380
381 <xsl:choose>
382 <xsl:when test="glossdiv and $collection//glossdiv">
383 <xsl:for-each select="$collection//glossdiv">
384 <!-- first see if there are any in this div -->
385 <xsl:variable name="exist.test">
386 <xsl:for-each select="glossentry">
387 <xsl:variable name="cterm" select="glossterm"/>
388 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
389 <xsl:value-of select="glossterm"/>
390 </xsl:if>
391 </xsl:for-each>
392 </xsl:variable>
393
394 <xsl:if test="$exist.test != ''">
395 <xsl:apply-templates select="." mode="auto-glossary">
396 <xsl:with-param name="terms" select="$terms"/>
397 </xsl:apply-templates>
398 </xsl:if>
399 </xsl:for-each>
400 </xsl:when>
401 <xsl:otherwise>
402 <dl>
403 <xsl:choose>
404 <xsl:when test="$glossary.sort != 0">
405 <xsl:for-each select="$collection//glossentry">
406 <xsl:sort lang="{$language}"
407 select="translate(glossterm, &lowercase;,
408 &uppercase;)"/>
409 <xsl:variable name="cterm" select="glossterm"/>
410 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
411 <xsl:apply-templates select="." mode="auto-glossary"/>
412 </xsl:if>
413 </xsl:for-each>
414 </xsl:when>
415 <xsl:otherwise>
416 <xsl:for-each select="$collection//glossentry">
417 <xsl:variable name="cterm" select="glossterm"/>
418 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
419 <xsl:apply-templates select="." mode="auto-glossary"/>
420 </xsl:if>
421 </xsl:for-each>
422 </xsl:otherwise>
423 </xsl:choose>
424 </dl>
425 </xsl:otherwise>
426 </xsl:choose>
427
428 <xsl:if test="not(parent::article)">
429 <xsl:call-template name="process.footnotes"/>
430 </xsl:if>
431 </div>
432 </xsl:template>
433
434 <xsl:template match="*" mode="auto-glossary">
435 <!-- pop back out to the default mode for most elements -->
436 <xsl:apply-templates select="."/>
437 </xsl:template>
438
439 <xsl:template match="glossdiv" mode="auto-glossary">
440 <xsl:param name="terms" select="."/>
441
442 <div>
443 <xsl:apply-templates select="." mode="class.attribute"/>
444 <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
445
446 <dl>
447 <xsl:choose>
448 <xsl:when test="$glossary.sort != 0">
449 <xsl:for-each select="glossentry">
450 <xsl:sort lang="{$language}"
451 select="translate(glossterm, &lowercase;,
452 &uppercase;)"/>
453 <xsl:variable name="cterm" select="glossterm"/>
454 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
455 <xsl:apply-templates select="." mode="auto-glossary"/>
456 </xsl:if>
457 </xsl:for-each>
458 </xsl:when>
459 <xsl:otherwise>
460 <xsl:for-each select="glossentry">
461 <xsl:variable name="cterm" select="glossterm"/>
462 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
463 <xsl:apply-templates select="." mode="auto-glossary"/>
464 </xsl:if>
465 </xsl:for-each>
466 </xsl:otherwise>
467 </xsl:choose>
468 </dl>
469 </div>
470 </xsl:template>
471
472 <!-- ==================================================================== -->
473
474 </xsl:stylesheet>