Project

General

Profile

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
                xmlns:xlink='http://www.w3.org/1999/xlink'
8
                exclude-result-prefixes="xlink"
9
                version='1.0'>
10

    
11
<!-- ********************************************************************
12
     $Id: glossary.xsl 8421 2009-05-04 07:49:49Z bobstayton $
13
     ********************************************************************
14

    
15
     This file is part of the XSL DocBook Stylesheet distribution.
16
     See ../README or http://docbook.sf.net/release/xsl/current/ for
17
     copyright and other information.
18

    
19
     ******************************************************************** -->
20

    
21
<!-- ==================================================================== -->
22

    
23
<xsl:template match="glossary">
24
  &setup-language-variable;
25
  <xsl:call-template name="id.warning"/>
26

    
27
  <div>
28
    <xsl:apply-templates select="." mode="common.html.attributes"/>
29
    <xsl:if test="$generate.id.attributes != 0">
30
      <xsl:attribute name="id">
31
        <xsl:call-template name="object.id"/>
32
      </xsl:attribute>
33
    </xsl:if>
34

    
35
    <xsl:call-template name="glossary.titlepage"/>
36

    
37
    <xsl:choose>
38
      <xsl:when test="glossdiv">
39
        <xsl:apply-templates select="(glossdiv[1]/preceding-sibling::*)"/>
40
      </xsl:when>
41
      <xsl:when test="glossentry">
42
        <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
43
      </xsl:when>
44
      <xsl:otherwise>
45
        <xsl:apply-templates/>
46
      </xsl:otherwise>
47
    </xsl:choose>
48

    
49
    <xsl:choose>
50
      <xsl:when test="glossdiv">
51
        <xsl:apply-templates select="glossdiv"/>
52
      </xsl:when>
53
      <xsl:when test="glossentry">
54
        <dl>
55
          <xsl:choose>
56
            <xsl:when test="$glossary.sort != 0">
57
              <xsl:apply-templates select="glossentry">
58
				<xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &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:when>
67
      <xsl:otherwise>
68
        <!-- empty glossary -->
69
      </xsl:otherwise>
70
    </xsl:choose>
71

    
72
    <xsl:if test="not(parent::article)">
73
      <xsl:call-template name="process.footnotes"/>
74
    </xsl:if>
75
  </div>
76
</xsl:template>
77

    
78
<xsl:template match="glossary/glossaryinfo"></xsl:template>
79
<xsl:template match="glossary/info"></xsl:template>
80
<xsl:template match="glossary/title"></xsl:template>
81
<xsl:template match="glossary/subtitle"></xsl:template>
82
<xsl:template match="glossary/titleabbrev"></xsl:template>
83

    
84
<!-- ==================================================================== -->
85

    
86
<xsl:template match="glosslist">
87
  &setup-language-variable;
88
  <div>
89
    <xsl:apply-templates select="." mode="common.html.attributes"/>
90
    <xsl:call-template name="anchor"/>
91
    <xsl:if test="blockinfo/title|info/title|title">
92
      <xsl:call-template name="formal.object.heading"/>
93
    </xsl:if>
94
    <dl>
95
      <xsl:choose>
96
        <xsl:when test="$glossary.sort != 0">
97
          <xsl:apply-templates select="glossentry">
98
				<xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
99
          </xsl:apply-templates>
100
        </xsl:when>
101
        <xsl:otherwise>
102
          <xsl:apply-templates select="glossentry"/>
103
        </xsl:otherwise>
104
      </xsl:choose>
105
    </dl>
106
  </div>
107
</xsl:template>
108

    
109
<!-- ==================================================================== -->
110

    
111
<xsl:template match="glossdiv">
112
  &setup-language-variable;
113
  <xsl:call-template name="id.warning"/>
114

    
115
  <div>
116
    <xsl:apply-templates select="." mode="common.html.attributes"/>
117
    <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
118

    
119
    <dl>
120
      <xsl:choose>
121
        <xsl:when test="$glossary.sort != 0">
122
          <xsl:apply-templates select="glossentry">
123
            <xsl:sort lang="{$language}"
124
                      select="translate(glossterm, $lowercase, 
125
                                        $uppercase)"/>
126
          </xsl:apply-templates>
127
        </xsl:when>
128
        <xsl:otherwise>
129
          <xsl:apply-templates select="glossentry"/>
130
        </xsl:otherwise>
131
      </xsl:choose>
132
    </dl>
133
  </div>
134
</xsl:template>
135

    
136
<xsl:template match="glossdiv/title">
137
  <h3>
138
    <xsl:apply-templates select="." mode="common.html.attributes"/>
139
    <xsl:apply-templates/>
140
  </h3>
141
</xsl:template>
142

    
143
<!-- ==================================================================== -->
144

    
145
<!--
146
GlossEntry ::=
147
  GlossTerm, Acronym?, Abbrev?,
148
  (IndexTerm)*,
149
  RevHistory?,
150
  (GlossSee | GlossDef+)
151
-->
152

    
153
<xsl:template match="glossentry">
154
  <xsl:choose>
155
    <xsl:when test="$glossentry.show.acronym = 'primary'">
156
      <dt>
157
        <xsl:call-template name="anchor">
158
          <xsl:with-param name="conditional">
159
            <xsl:choose>
160
              <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
161
              <xsl:otherwise>1</xsl:otherwise>
162
            </xsl:choose>
163
          </xsl:with-param>
164
        </xsl:call-template>
165

    
166
        <xsl:choose>
167
          <xsl:when test="acronym|abbrev">
168
            <xsl:apply-templates select="acronym|abbrev"/>
169
            <xsl:text> (</xsl:text>
170
            <xsl:apply-templates select="glossterm"/>
171
            <xsl:text>)</xsl:text>
172
          </xsl:when>
173
          <xsl:otherwise>
174
            <xsl:apply-templates select="glossterm"/>
175
          </xsl:otherwise>
176
        </xsl:choose>
177
      </dt>
178
    </xsl:when>
179
    <xsl:when test="$glossentry.show.acronym = 'yes'">
180
      <dt>
181
        <xsl:call-template name="anchor">
182
          <xsl:with-param name="conditional">
183
            <xsl:choose>
184
              <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
185
              <xsl:otherwise>1</xsl:otherwise>
186
            </xsl:choose>
187
          </xsl:with-param>
188
        </xsl:call-template>
189

    
190
        <xsl:apply-templates select="glossterm"/>
191

    
192
        <xsl:if test="acronym|abbrev">
193
          <xsl:text> (</xsl:text>
194
          <xsl:apply-templates select="acronym|abbrev"/>
195
          <xsl:text>)</xsl:text>
196
        </xsl:if>
197
      </dt>
198
    </xsl:when>
199
    <xsl:otherwise>
200
      <dt>
201
        <xsl:call-template name="anchor">
202
          <xsl:with-param name="conditional">
203
            <xsl:choose>
204
              <xsl:when test="$glossterm.auto.link != 0">0</xsl:when>
205
              <xsl:otherwise>1</xsl:otherwise>
206
            </xsl:choose>
207
          </xsl:with-param>
208
        </xsl:call-template>
209

    
210
        <xsl:apply-templates select="glossterm"/>
211
      </dt>
212
    </xsl:otherwise>
213
  </xsl:choose>
214

    
215
  <xsl:apply-templates select="indexterm|revhistory|glosssee|glossdef"/>
216
</xsl:template>
217

    
218
<xsl:template match="glossentry/glossterm">
219
  <xsl:apply-templates/>
220
  <xsl:if test="following-sibling::glossterm">, </xsl:if>
221
</xsl:template>
222

    
223
<xsl:template match="glossentry/acronym">
224
  <xsl:apply-templates/>
225
  <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
226
</xsl:template>
227

    
228
<xsl:template match="glossentry/abbrev">
229
  <xsl:apply-templates/>
230
  <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
231
</xsl:template>
232

    
233
<xsl:template match="glossentry/revhistory">
234
</xsl:template>
235

    
236
<xsl:template match="glossentry/glosssee">
237
  <xsl:variable name="otherterm" select="@otherterm"/>
238
  <xsl:variable name="targets" select="key('id', $otherterm)"/>
239
  <xsl:variable name="target" select="$targets[1]"/>
240
  <xsl:variable name="xlink" select="@xlink:href"/>
241

    
242
  <dd>
243
    <p>
244
      <xsl:variable name="template">
245
        <xsl:call-template name="gentext.template">
246
          <xsl:with-param name="context" select="'glossary'"/>
247
          <xsl:with-param name="name" select="'see'"/>
248
        </xsl:call-template>
249
      </xsl:variable>
250

    
251
      <xsl:variable name="title">
252
        <xsl:choose>
253
          <xsl:when test="$target">
254
            <a>
255
              <xsl:apply-templates select="." mode="common.html.attributes"/>
256
              <xsl:attribute name="href">
257
                <xsl:call-template name="href.target">
258
                  <xsl:with-param name="object" select="$target"/>
259
                </xsl:call-template>
260
              </xsl:attribute>
261
              <xsl:apply-templates select="$target" mode="xref-to"/>
262
            </a>
263
          </xsl:when>
264
          <xsl:when test="$xlink">
265
            <xsl:call-template name="simple.xlink">
266
              <xsl:with-param name="content">
267
                <xsl:apply-templates/>
268
              </xsl:with-param>
269
            </xsl:call-template>
270
          </xsl:when>
271
          <xsl:when test="$otherterm != '' and not($target)">
272
            <xsl:message>
273
              <xsl:text>Warning: glosssee @otherterm reference not found: </xsl:text>
274
              <xsl:value-of select="$otherterm"/>
275
            </xsl:message>
276
            <xsl:apply-templates/>
277
          </xsl:when>
278
          <xsl:otherwise>
279
            <xsl:apply-templates/>
280
          </xsl:otherwise>
281
        </xsl:choose>
282
      </xsl:variable>
283

    
284
      <xsl:call-template name="substitute-markup">
285
        <xsl:with-param name="template" select="$template"/>
286
        <xsl:with-param name="title" select="$title"/>
287
      </xsl:call-template>
288
    </p>
289
  </dd>
290
</xsl:template>
291

    
292
<xsl:template match="glossentry/glossdef">
293
  <dd>
294
    <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"/>
295
    <xsl:if test="glossseealso">
296
      <p>
297
        <xsl:variable name="template">
298
          <xsl:call-template name="gentext.template">
299
            <xsl:with-param name="context" select="'glossary'"/>
300
            <xsl:with-param name="name" select="'seealso'"/>
301
          </xsl:call-template>
302
        </xsl:variable>
303
        <xsl:variable name="title">
304
          <xsl:apply-templates select="glossseealso"/>
305
        </xsl:variable>
306
        <xsl:call-template name="substitute-markup">
307
          <xsl:with-param name="template" select="$template"/>
308
          <xsl:with-param name="title" select="$title"/>
309
        </xsl:call-template>
310
      </p>
311
    </xsl:if>
312
  </dd>
313
</xsl:template>
314

    
315
<xsl:template match="glossseealso">
316
  <xsl:variable name="otherterm" select="@otherterm"/>
317
  <xsl:variable name="targets" select="key('id', $otherterm)"/>
318
  <xsl:variable name="target" select="$targets[1]"/>
319
  <xsl:variable name="xlink" select="@xlink:href"/>
320

    
321
  <xsl:choose>
322
    <xsl:when test="$target">
323
      <a>
324
        <xsl:apply-templates select="." mode="common.html.attributes"/>
325
        <xsl:attribute name="href">
326
          <xsl:call-template name="href.target">
327
            <xsl:with-param name="object" select="$target"/>
328
          </xsl:call-template>
329
        </xsl:attribute>
330
        <xsl:apply-templates select="$target" mode="xref-to"/>
331
      </a>
332
    </xsl:when>
333
    <xsl:when test="$xlink">
334
      <xsl:call-template name="simple.xlink">
335
        <xsl:with-param name="content">
336
          <xsl:apply-templates/>
337
        </xsl:with-param>
338
      </xsl:call-template>
339
    </xsl:when>
340
    <xsl:when test="$otherterm != '' and not($target)">
341
      <xsl:message>
342
        <xsl:text>Warning: glossseealso @otherterm reference not found: </xsl:text>
343
        <xsl:value-of select="$otherterm"/>
344
      </xsl:message>
345
      <xsl:apply-templates/>
346
    </xsl:when>
347
    <xsl:otherwise>
348
      <xsl:apply-templates/>
349
    </xsl:otherwise>
350
  </xsl:choose>
351

    
352
  <xsl:choose>
353
    <xsl:when test="position() = last()"/>
354
    <xsl:otherwise>
355
		<xsl:call-template name="gentext.template">
356
		  <xsl:with-param name="context" select="'glossary'"/>
357
		  <xsl:with-param name="name" select="'seealso-separator'"/>
358
		</xsl:call-template>
359
    </xsl:otherwise>
360
  </xsl:choose>
361
</xsl:template>
362

    
363
<!-- ==================================================================== -->
364

    
365
<!-- Glossary collection -->
366

    
367
<xsl:template match="glossary[@role='auto']" priority="2">
368
  &setup-language-variable;
369
  <xsl:variable name="terms" 
370
                select="//glossterm[not(parent::glossdef)]|//firstterm"/>
371
  <xsl:variable name="collection" select="document($glossary.collection, .)"/>
372

    
373
  <xsl:call-template name="id.warning"/>
374

    
375
  <xsl:if test="$glossary.collection = ''">
376
    <xsl:message>
377
      <xsl:text>Warning: processing automatic glossary </xsl:text>
378
      <xsl:text>without a glossary.collection file.</xsl:text>
379
    </xsl:message>
380
  </xsl:if>
381

    
382
  <xsl:if test="not($collection) and $glossary.collection != ''">
383
    <xsl:message>
384
      <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
385
      <xsl:text>open glossary.collection file '</xsl:text>
386
      <xsl:value-of select="$glossary.collection"/>
387
      <xsl:text>'</xsl:text>
388
    </xsl:message>
389
  </xsl:if>
390

    
391
  <div>
392
    <xsl:apply-templates select="." mode="common.html.attributes"/>
393
    <xsl:if test="$generate.id.attributes != 0">
394
      <xsl:attribute name="id">
395
        <xsl:call-template name="object.id"/>
396
      </xsl:attribute>
397
    </xsl:if>
398

    
399
    <xsl:call-template name="glossary.titlepage"/>
400

    
401
    <xsl:choose>
402
      <xsl:when test="glossdiv and $collection//glossdiv">
403
        <xsl:for-each select="$collection//glossdiv">
404
          <!-- first see if there are any in this div -->
405
          <xsl:variable name="exist.test">
406
            <xsl:for-each select="glossentry">
407
              <xsl:variable name="cterm" select="glossterm"/>
408
              <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
409
                <xsl:value-of select="glossterm"/>
410
              </xsl:if>
411
            </xsl:for-each>
412
          </xsl:variable>
413

    
414
          <xsl:if test="$exist.test != ''">
415
            <xsl:apply-templates select="." mode="auto-glossary">
416
              <xsl:with-param name="terms" select="$terms"/>
417
            </xsl:apply-templates>
418
          </xsl:if>
419
        </xsl:for-each>
420
      </xsl:when>
421
      <xsl:otherwise>
422
        <dl>
423
          <xsl:choose>
424
            <xsl:when test="$glossary.sort != 0">
425
              <xsl:for-each select="$collection//glossentry">
426
				<xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
427
                <xsl:variable name="cterm" select="glossterm"/>
428
                <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
429
                  <xsl:apply-templates select="." mode="auto-glossary"/>
430
                </xsl:if>
431
              </xsl:for-each>
432
            </xsl:when>
433
            <xsl:otherwise>
434
              <xsl:for-each select="$collection//glossentry">
435
                <xsl:variable name="cterm" select="glossterm"/>
436
                <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
437
                  <xsl:apply-templates select="." mode="auto-glossary"/>
438
                </xsl:if>
439
              </xsl:for-each>
440
            </xsl:otherwise>
441
          </xsl:choose>
442
        </dl>
443
      </xsl:otherwise>
444
    </xsl:choose>
445

    
446
    <xsl:if test="not(parent::article)">
447
      <xsl:call-template name="process.footnotes"/>
448
    </xsl:if>
449
  </div>
450
</xsl:template>
451

    
452
<xsl:template match="*" mode="auto-glossary">
453
  <!-- pop back out to the default mode for most elements -->
454
  <xsl:apply-templates select="."/>
455
</xsl:template>
456

    
457
<xsl:template match="glossdiv" mode="auto-glossary">
458
  <xsl:param name="terms" select="."/>
459

    
460
  &setup-language-variable;
461

    
462
  <div>
463
    <xsl:apply-templates select="." mode="common.html.attributes"/>
464
    <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/>
465

    
466
    <dl>
467
      <xsl:choose>
468
        <xsl:when test="$glossary.sort != 0">
469
          <xsl:for-each select="glossentry">
470
				<xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>!
471
            <xsl:variable name="cterm" select="glossterm"/>
472
            <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
473
              <xsl:apply-templates select="." mode="auto-glossary"/>
474
            </xsl:if>
475
          </xsl:for-each>
476
        </xsl:when>
477
        <xsl:otherwise>
478
          <xsl:for-each select="glossentry">
479
            <xsl:variable name="cterm" select="glossterm"/>
480
            <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
481
              <xsl:apply-templates select="." mode="auto-glossary"/>
482
            </xsl:if>
483
          </xsl:for-each>
484
        </xsl:otherwise>
485
      </xsl:choose>
486
    </dl>
487
  </div>
488
</xsl:template>
489

    
490
<!-- ==================================================================== -->
491

    
492
</xsl:stylesheet>
(16-16/39)