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