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