]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/evergreen_docbook_files/docbook-xsl-1.75.2/fo/glossary.xsl
Capitalized the start of a sentence in the bucket section of cataloging.
[working/Evergreen.git] / stylesheets / evergreen_docbook_files / docbook-xsl-1.75.2 / fo / glossary.xsl
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:fo="http://www.w3.org/1999/XSL/Format"
8                 xmlns:xlink='http://www.w3.org/1999/xlink'
9                 exclude-result-prefixes="xlink"
10                 version='1.0'>
11
12 <!-- ********************************************************************
13      $Id: glossary.xsl 8393 2009-04-02 14:20:44Z dcramer $
14      ********************************************************************
15
16      This file is part of the XSL DocBook Stylesheet distribution.
17      See ../README or http://docbook.sf.net/release/xsl/current/ for
18      copyright and other information.
19
20      ******************************************************************** -->
21
22 <!-- ==================================================================== -->
23
24 <xsl:template match="glossary">
25   <xsl:call-template name="make-glossary"/>
26 </xsl:template>
27
28 <xsl:template match="glossdiv/title"/>
29 <xsl:template match="glossdiv/subtitle"/>
30 <xsl:template match="glossdiv/titleabbrev"/>
31
32 <!-- ==================================================================== -->
33
34 <xsl:template name="make-glossary">
35   <xsl:param name="divs" select="glossdiv"/>
36   <xsl:param name="entries" select="glossentry"/>
37   <xsl:param name="preamble" select="*[not(self::title
38                                            or self::subtitle
39                                            or self::glossdiv
40                                            or self::glossentry)]"/>
41
42   &setup-language-variable;
43
44   <xsl:variable name="id">
45     <xsl:call-template name="object.id"/>
46   </xsl:variable>
47
48   <xsl:variable name="presentation">
49     <xsl:call-template name="pi.dbfo_glossary-presentation"/>
50   </xsl:variable>
51
52   <xsl:variable name="term-width">
53     <xsl:call-template name="pi.dbfo_glossterm-width"/>
54   </xsl:variable>
55
56   <xsl:variable name="width">
57     <xsl:choose>
58       <xsl:when test="$term-width = ''">
59         <xsl:value-of select="$glossterm.width"/>
60       </xsl:when>
61       <xsl:otherwise>
62         <xsl:value-of select="$term-width"/>
63       </xsl:otherwise>
64     </xsl:choose>
65   </xsl:variable>
66
67   <fo:block id="{$id}">
68     <xsl:call-template name="glossary.titlepage"/>
69   </fo:block>
70
71   <xsl:if test="$preamble">
72     <xsl:apply-templates select="$preamble"/>
73   </xsl:if>
74
75   <xsl:choose>
76     <xsl:when test="$presentation = 'list'">
77       <xsl:apply-templates select="$divs" mode="glossary.as.list">
78         <xsl:with-param name="width" select="$width"/>
79       </xsl:apply-templates>
80       <xsl:if test="$entries">
81         <fo:list-block provisional-distance-between-starts="{$width}"
82                        provisional-label-separation="{$glossterm.separation}"
83                        xsl:use-attribute-sets="normal.para.spacing">
84           <xsl:choose>
85             <xsl:when test="$glossary.sort != 0">
86               <xsl:apply-templates select="$entries" mode="glossary.as.list">
87                                   <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
88               </xsl:apply-templates>
89             </xsl:when>
90             <xsl:otherwise>
91               <xsl:apply-templates select="$entries" mode="glossary.as.list"/>
92             </xsl:otherwise>
93           </xsl:choose>
94         </fo:list-block>
95       </xsl:if>
96     </xsl:when>
97     <xsl:when test="$presentation = 'blocks'">
98       <xsl:apply-templates select="$divs" mode="glossary.as.blocks"/>
99       <xsl:choose>
100         <xsl:when test="$glossary.sort != 0">
101           <xsl:apply-templates select="$entries" mode="glossary.as.blocks">
102                           <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
103           </xsl:apply-templates>
104         </xsl:when>
105         <xsl:otherwise>
106           <xsl:apply-templates select="$entries" mode="glossary.as.blocks"/>
107         </xsl:otherwise>
108       </xsl:choose>
109     </xsl:when>
110     <xsl:when test="$glossary.as.blocks != 0">
111       <xsl:apply-templates select="$divs" mode="glossary.as.blocks"/>
112       <xsl:choose>
113         <xsl:when test="$glossary.sort != 0">
114           <xsl:apply-templates select="$entries" mode="glossary.as.blocks">
115                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
116           </xsl:apply-templates>
117         </xsl:when>
118         <xsl:otherwise>
119           <xsl:apply-templates select="$entries" mode="glossary.as.blocks"/>
120         </xsl:otherwise>
121       </xsl:choose>
122     </xsl:when>
123     <xsl:otherwise>
124       <xsl:apply-templates select="$divs" mode="glossary.as.list">
125         <xsl:with-param name="width" select="$width"/>
126       </xsl:apply-templates>
127       <xsl:if test="$entries">
128         <fo:list-block provisional-distance-between-starts="{$width}"
129                        provisional-label-separation="{$glossterm.separation}"
130                        xsl:use-attribute-sets="normal.para.spacing">
131           <xsl:choose>
132             <xsl:when test="$glossary.sort != 0">
133               <xsl:apply-templates select="$entries" mode="glossary.as.list">
134                                         <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
135               </xsl:apply-templates>
136             </xsl:when>
137             <xsl:otherwise>
138               <xsl:apply-templates select="$entries" mode="glossary.as.list"/>
139             </xsl:otherwise>
140           </xsl:choose>
141         </fo:list-block>
142       </xsl:if>
143     </xsl:otherwise>
144   </xsl:choose>
145 </xsl:template>
146
147 <xsl:template match="book/glossary|part/glossary|/glossary" priority="2">
148   <xsl:variable name="id">
149     <xsl:call-template name="object.id"/>
150   </xsl:variable>
151
152   <xsl:variable name="master-reference">
153     <xsl:call-template name="select.pagemaster"/>
154   </xsl:variable>
155
156   <fo:page-sequence hyphenate="{$hyphenate}"
157                     master-reference="{$master-reference}">
158     <xsl:attribute name="language">
159       <xsl:call-template name="l10n.language"/>
160     </xsl:attribute>
161
162     <xsl:attribute name="format">
163       <xsl:call-template name="page.number.format">
164         <xsl:with-param name="master-reference" select="$master-reference"/>
165       </xsl:call-template>
166     </xsl:attribute>
167     
168     <xsl:attribute name="initial-page-number">
169       <xsl:call-template name="initial.page.number">
170         <xsl:with-param name="master-reference" select="$master-reference"/>
171       </xsl:call-template>
172     </xsl:attribute>
173
174     <xsl:attribute name="force-page-count">
175       <xsl:call-template name="force.page.count">
176         <xsl:with-param name="master-reference" select="$master-reference"/>
177       </xsl:call-template>
178     </xsl:attribute>
179
180     <xsl:attribute name="hyphenation-character">
181       <xsl:call-template name="gentext">
182         <xsl:with-param name="key" select="'hyphenation-character'"/>
183       </xsl:call-template>
184     </xsl:attribute>
185     <xsl:attribute name="hyphenation-push-character-count">
186       <xsl:call-template name="gentext">
187         <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
188       </xsl:call-template>
189     </xsl:attribute>
190     <xsl:attribute name="hyphenation-remain-character-count">
191       <xsl:call-template name="gentext">
192         <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
193       </xsl:call-template>
194     </xsl:attribute>
195
196     <xsl:apply-templates select="." mode="running.head.mode">
197       <xsl:with-param name="master-reference" select="$master-reference"/>
198     </xsl:apply-templates>
199     <xsl:apply-templates select="." mode="running.foot.mode">
200       <xsl:with-param name="master-reference" select="$master-reference"/>
201     </xsl:apply-templates>
202
203     <fo:flow flow-name="xsl-region-body">
204       <xsl:call-template name="set.flow.properties">
205         <xsl:with-param name="element" select="local-name(.)"/>
206         <xsl:with-param name="master-reference" select="$master-reference"/>
207       </xsl:call-template>
208
209       <xsl:call-template name="make-glossary"/>
210     </fo:flow>
211   </fo:page-sequence>
212 </xsl:template>
213
214 <xsl:template match="glossary/glossaryinfo"></xsl:template>
215 <xsl:template match="glossary/info"></xsl:template>
216 <xsl:template match="glossary/title"></xsl:template>
217 <xsl:template match="glossary/subtitle"></xsl:template>
218 <xsl:template match="glossary/titleabbrev"></xsl:template>
219
220 <!-- ==================================================================== -->
221
222 <xsl:template match="glosslist">
223   &setup-language-variable;
224
225   <xsl:variable name="presentation">
226     <xsl:call-template name="pi.dbfo_glosslist-presentation"/>
227   </xsl:variable>
228
229   <xsl:variable name="term-width">
230     <xsl:call-template name="pi.dbfo_glossterm-width"/>
231   </xsl:variable>
232
233   <xsl:variable name="width">
234     <xsl:choose>
235       <xsl:when test="$term-width = ''">
236         <xsl:value-of select="$glossterm.width"/>
237       </xsl:when>
238       <xsl:otherwise>
239         <xsl:value-of select="$term-width"/>
240       </xsl:otherwise>
241     </xsl:choose>
242   </xsl:variable>
243
244   <xsl:if test="title or info/title">
245     <xsl:apply-templates select="(title|info/title)[1]" mode="list.title.mode"/>
246   </xsl:if>
247
248   <xsl:choose>
249     <xsl:when test="$presentation = 'list'">
250       <fo:list-block provisional-distance-between-starts="{$width}"
251                      provisional-label-separation="{$glossterm.separation}"
252                      xsl:use-attribute-sets="normal.para.spacing">
253         <xsl:choose>
254           <xsl:when test="$glossary.sort != 0">
255             <xsl:apply-templates select="glossentry" mode="glossary.as.list">
256                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
257             </xsl:apply-templates>
258           </xsl:when>
259           <xsl:otherwise>
260             <xsl:apply-templates select="glossentry" mode="glossary.as.list"/>
261           </xsl:otherwise>
262         </xsl:choose>
263       </fo:list-block>
264     </xsl:when>
265     <xsl:when test="$presentation = 'blocks'">
266       <xsl:choose>
267         <xsl:when test="$glossary.sort != 0">
268           <xsl:apply-templates select="glossentry" mode="glossary.as.blocks">
269                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
270           </xsl:apply-templates>
271         </xsl:when>
272         <xsl:otherwise>
273           <xsl:apply-templates select="glossentry" mode="glossary.as.blocks"/>
274         </xsl:otherwise>
275       </xsl:choose>
276     </xsl:when>
277     <xsl:when test="$glosslist.as.blocks != 0">
278       <xsl:choose>
279         <xsl:when test="$glossary.sort != 0">
280           <xsl:apply-templates select="glossentry" mode="glossary.as.blocks">
281                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
282           </xsl:apply-templates>
283         </xsl:when>
284         <xsl:otherwise>
285           <xsl:apply-templates select="glossentry" mode="glossary.as.blocks"/>
286         </xsl:otherwise>
287       </xsl:choose>
288     </xsl:when>
289     <xsl:otherwise>
290       <fo:list-block provisional-distance-between-starts="{$width}"
291                      provisional-label-separation="{$glossterm.separation}"
292                      xsl:use-attribute-sets="normal.para.spacing">
293         <xsl:choose>
294           <xsl:when test="$glossary.sort != 0">
295             <xsl:apply-templates select="glossentry" mode="glossary.as.list">
296                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
297             </xsl:apply-templates>
298           </xsl:when>
299           <xsl:otherwise>
300             <xsl:apply-templates select="glossentry" mode="glossary.as.list"/>
301           </xsl:otherwise>
302         </xsl:choose>
303       </fo:list-block>
304     </xsl:otherwise>
305   </xsl:choose>
306 </xsl:template>
307
308 <!-- ==================================================================== -->
309 <!-- Glossary collection -->
310
311 <xsl:template match="glossary[@role='auto']" priority="2">
312   <xsl:variable name="collection" select="document($glossary.collection, .)"/>
313   <xsl:if test="$glossary.collection = ''">
314     <xsl:message>
315       <xsl:text>Warning: processing automatic glossary </xsl:text>
316       <xsl:text>without a glossary.collection file.</xsl:text>
317     </xsl:message>
318   </xsl:if>
319
320   <xsl:if test="not($collection) and $glossary.collection != ''">
321     <xsl:message>
322       <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
323       <xsl:text>open glossary.collection file '</xsl:text>
324       <xsl:value-of select="$glossary.collection"/>
325       <xsl:text>'</xsl:text>
326     </xsl:message>
327   </xsl:if>
328
329   <xsl:call-template name="make-auto-glossary"/>
330 </xsl:template>
331
332 <xsl:template name="make-auto-glossary">
333   <xsl:param name="collection" select="document($glossary.collection, .)"/>
334   <xsl:param name="terms" select="//glossterm[not(parent::glossdef)]|//firstterm"/>
335   <xsl:param name="preamble" select="*[not(self::title
336                                            or self::subtitle
337                                            or self::glossdiv
338                                            or self::glossentry)]"/>
339
340   &setup-language-variable;
341
342   <xsl:variable name="id">
343     <xsl:call-template name="object.id"/>
344   </xsl:variable>
345
346   <xsl:variable name="presentation">
347     <xsl:call-template name="pi.dbfo_glossary-presentation"/>
348   </xsl:variable>
349
350   <xsl:variable name="term-width">
351     <xsl:call-template name="pi.dbfo_glossterm-width"/>
352   </xsl:variable>
353
354   <xsl:variable name="width">
355     <xsl:choose>
356       <xsl:when test="$term-width = ''">
357         <xsl:value-of select="$glossterm.width"/>
358       </xsl:when>
359       <xsl:otherwise>
360         <xsl:value-of select="$term-width"/>
361       </xsl:otherwise>
362     </xsl:choose>
363   </xsl:variable>
364
365   <xsl:if test="$glossary.collection = ''">
366     <xsl:message>
367       <xsl:text>Warning: processing automatic glossary </xsl:text>
368       <xsl:text>without a glossary.collection file.</xsl:text>
369     </xsl:message>
370   </xsl:if>
371
372   <fo:block id="{$id}">
373     <xsl:call-template name="glossary.titlepage"/>
374   </fo:block>
375
376   <xsl:if test="$preamble">
377     <xsl:apply-templates select="$preamble"/>
378   </xsl:if>
379
380   <xsl:choose>
381     <xsl:when test="glossdiv and $collection//glossdiv">
382       <xsl:for-each select="$collection//glossdiv">
383         <!-- first see if there are any in this div -->
384         <xsl:variable name="exist.test">
385           <xsl:for-each select="glossentry">
386             <xsl:variable name="cterm" select="glossterm"/>
387             <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
388               <xsl:value-of select="glossterm"/>
389             </xsl:if>
390           </xsl:for-each>
391         </xsl:variable>
392
393         <xsl:if test="$exist.test != ''">
394           <xsl:choose>
395             <xsl:when test="$presentation = 'list'">
396               <xsl:apply-templates select="." mode="auto-glossary-as-list">
397                 <xsl:with-param name="width" select="$width"/>
398                 <xsl:with-param name="terms" select="$terms"/>
399               </xsl:apply-templates>
400             </xsl:when>
401             <xsl:when test="$presentation = 'blocks'">
402               <xsl:apply-templates select="." mode="auto-glossary-as-blocks">
403                 <xsl:with-param name="terms" select="$terms"/>
404               </xsl:apply-templates>
405             </xsl:when>
406             <xsl:when test="$glossary.as.blocks != 0">
407               <xsl:apply-templates select="." mode="auto-glossary-as-blocks">
408                 <xsl:with-param name="terms" select="$terms"/>
409               </xsl:apply-templates>
410             </xsl:when>
411             <xsl:otherwise>
412               <xsl:apply-templates select="." mode="auto-glossary-as-list">
413                 <xsl:with-param name="width" select="$width"/>
414                 <xsl:with-param name="terms" select="$terms"/>
415               </xsl:apply-templates>
416             </xsl:otherwise>
417           </xsl:choose>
418         </xsl:if>
419       </xsl:for-each>
420     </xsl:when>
421     <xsl:otherwise>
422       <xsl:choose>
423         <xsl:when test="$presentation = 'list'">
424           <fo:list-block provisional-distance-between-starts="{$width}"
425                          provisional-label-separation="{$glossterm.separation}"
426                          xsl:use-attribute-sets="normal.para.spacing">
427             <xsl:choose>
428               <xsl:when test="$glossary.sort != 0">
429                 <xsl:for-each select="$collection//glossentry">
430                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
431                   <xsl:variable name="cterm" select="glossterm"/>
432                   <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
433                     <xsl:apply-templates select="." 
434                                          mode="auto-glossary-as-list"/>
435                   </xsl:if>
436                 </xsl:for-each>
437               </xsl:when>
438               <xsl:otherwise>
439                 <xsl:for-each select="$collection//glossentry">
440                   <xsl:variable name="cterm" select="glossterm"/>
441                   <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
442                     <xsl:apply-templates select="." 
443                                          mode="auto-glossary-as-list"/>
444                   </xsl:if>
445                 </xsl:for-each>
446               </xsl:otherwise>
447             </xsl:choose>
448           </fo:list-block>
449         </xsl:when>
450         <xsl:when test="$presentation = 'blocks' or
451                         $glossary.as.blocks != 0">
452           <xsl:choose>
453             <xsl:when test="$glossary.sort != 0">
454               <xsl:for-each select="$collection//glossentry">
455                                         <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
456                 <xsl:variable name="cterm" select="glossterm"/>
457                 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
458                   <xsl:apply-templates select="." 
459                                        mode="auto-glossary-as-blocks"/>
460                 </xsl:if>
461               </xsl:for-each>
462             </xsl:when>
463             <xsl:otherwise>
464               <xsl:for-each select="$collection//glossentry">
465                 <xsl:variable name="cterm" select="glossterm"/>
466                 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
467                   <xsl:apply-templates select="." 
468                                        mode="auto-glossary-as-blocks"/>
469                 </xsl:if>
470               </xsl:for-each>
471             </xsl:otherwise>
472           </xsl:choose>
473         </xsl:when>
474         <xsl:otherwise>
475           <fo:list-block provisional-distance-between-starts="{$width}"
476                          provisional-label-separation="{$glossterm.separation}"
477                          xsl:use-attribute-sets="normal.para.spacing">
478             <xsl:choose>
479               <xsl:when test="$glossary.sort != 0">
480                 <xsl:for-each select="$collection//glossentry">
481
482                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
483                   <xsl:variable name="cterm" select="glossterm"/>
484                   <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
485                     <xsl:apply-templates select="." 
486                                          mode="auto-glossary-as-list"/>
487                   </xsl:if>
488                 </xsl:for-each>
489               </xsl:when>
490               <xsl:otherwise>
491                 <xsl:for-each select="$collection//glossentry">
492                   <xsl:variable name="cterm" select="glossterm"/>
493                   <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
494                     <xsl:apply-templates select="." 
495                                          mode="auto-glossary-as-list"/>
496                   </xsl:if>
497                 </xsl:for-each>
498               </xsl:otherwise>
499             </xsl:choose>
500           </fo:list-block>
501         </xsl:otherwise>
502       </xsl:choose>
503     </xsl:otherwise>
504   </xsl:choose>
505 </xsl:template>
506
507 <xsl:template match="book/glossary[@role='auto']|
508                      part/glossary[@role='auto']|
509                      /glossary[@role='auto']" priority="2.5">
510   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
511
512   <xsl:variable name="master-reference">
513     <xsl:call-template name="select.pagemaster"/>
514   </xsl:variable>
515
516   <xsl:if test="$glossary.collection = ''">
517     <xsl:message>
518       <xsl:text>Warning: processing automatic glossary </xsl:text>
519       <xsl:text>without a glossary.collection file.</xsl:text>
520     </xsl:message>
521   </xsl:if>
522
523   <fo:page-sequence hyphenate="{$hyphenate}"
524                     master-reference="{$master-reference}">
525     <xsl:attribute name="language">
526       <xsl:call-template name="l10n.language"/>
527     </xsl:attribute>
528     <xsl:attribute name="format">
529       <xsl:call-template name="page.number.format">
530         <xsl:with-param name="master-reference" select="$master-reference"/>
531       </xsl:call-template>
532     </xsl:attribute>
533
534     <xsl:attribute name="initial-page-number">
535       <xsl:call-template name="initial.page.number">
536         <xsl:with-param name="master-reference" select="$master-reference"/>
537       </xsl:call-template>
538     </xsl:attribute>
539
540     <xsl:attribute name="force-page-count">
541       <xsl:call-template name="force.page.count">
542         <xsl:with-param name="master-reference" select="$master-reference"/>
543       </xsl:call-template>
544     </xsl:attribute>
545
546     <xsl:attribute name="hyphenation-character">
547       <xsl:call-template name="gentext">
548         <xsl:with-param name="key" select="'hyphenation-character'"/>
549       </xsl:call-template>
550     </xsl:attribute>
551     <xsl:attribute name="hyphenation-push-character-count">
552       <xsl:call-template name="gentext">
553         <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
554       </xsl:call-template>
555     </xsl:attribute>
556     <xsl:attribute name="hyphenation-remain-character-count">
557       <xsl:call-template name="gentext">
558         <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
559       </xsl:call-template>
560     </xsl:attribute>
561
562     <xsl:apply-templates select="." mode="running.head.mode">
563       <xsl:with-param name="master-reference" select="$master-reference"/>
564     </xsl:apply-templates>
565     <xsl:apply-templates select="." mode="running.foot.mode">
566       <xsl:with-param name="master-reference" select="$master-reference"/>
567     </xsl:apply-templates>
568
569     <fo:flow flow-name="xsl-region-body">
570       <xsl:call-template name="set.flow.properties">
571         <xsl:with-param name="element" select="local-name(.)"/>
572         <xsl:with-param name="master-reference" select="$master-reference"/>
573       </xsl:call-template>
574
575       <xsl:call-template name="make-auto-glossary"/>
576     </fo:flow>
577   </fo:page-sequence>
578 </xsl:template>
579
580 <xsl:template match="glossdiv" mode="auto-glossary-as-list">
581   <xsl:param name="width" select="$glossterm.width"/>
582   <xsl:param name="terms" select="."/>
583
584   &setup-language-variable;
585
586   <xsl:variable name="preamble"
587                 select="*[not(self::title
588                             or self::subtitle
589                             or self::glossentry)]"/>
590
591   <xsl:call-template name="glossdiv.titlepage"/>
592
593   <xsl:apply-templates select="$preamble"/>
594
595   <fo:list-block provisional-distance-between-starts="{$width}"
596                  provisional-label-separation="{$glossterm.separation}"
597                  xsl:use-attribute-sets="normal.para.spacing">
598     <xsl:choose>
599       <xsl:when test="$glossary.sort != 0">
600         <xsl:for-each select="glossentry">
601                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
602           <xsl:variable name="cterm" select="glossterm"/>
603           <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
604             <xsl:apply-templates select="." mode="auto-glossary-as-list"/>
605           </xsl:if>
606         </xsl:for-each>
607       </xsl:when>
608       <xsl:otherwise>
609         <xsl:for-each select="glossentry">
610           <xsl:variable name="cterm" select="glossterm"/>
611           <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
612             <xsl:apply-templates select="." mode="auto-glossary-as-list"/>
613           </xsl:if>
614         </xsl:for-each>
615       </xsl:otherwise>
616     </xsl:choose>
617   </fo:list-block>
618 </xsl:template>
619
620 <xsl:template match="glossentry" mode="auto-glossary-as-list">
621   <xsl:apply-templates select="." mode="glossary.as.list"/>
622 </xsl:template>
623
624 <xsl:template match="glossdiv" mode="auto-glossary-as-blocks">
625   <xsl:param name="terms" select="."/>
626
627   &setup-language-variable;
628
629   <xsl:variable name="preamble"
630                 select="*[not(self::title
631                             or self::subtitle
632                             or self::glossentry)]"/>
633
634   <xsl:call-template name="glossdiv.titlepage"/>
635
636   <xsl:apply-templates select="$preamble"/>
637
638   <xsl:choose>
639     <xsl:when test="$glossary.sort != 0">
640       <xsl:for-each select="glossentry">
641                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
642         <xsl:variable name="cterm" select="glossterm"/>
643         <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
644           <xsl:apply-templates select="." mode="auto-glossary-as-blocks"/>
645         </xsl:if>
646       </xsl:for-each>
647     </xsl:when>
648     <xsl:otherwise>
649       <xsl:for-each select="glossentry">
650         <xsl:variable name="cterm" select="glossterm"/>
651         <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
652           <xsl:apply-templates select="." mode="auto-glossary-as-blocks"/>
653         </xsl:if>
654       </xsl:for-each>
655     </xsl:otherwise>
656   </xsl:choose>
657
658 </xsl:template>
659
660 <xsl:template match="glossentry" mode="auto-glossary-as-blocks">
661   <xsl:apply-templates select="." mode="glossary.as.blocks"/>
662 </xsl:template>
663
664 <!-- ==================================================================== -->
665 <!-- Format glossary as a list -->
666
667 <xsl:template match="glossdiv" mode="glossary.as.list">
668   <xsl:param name="width" select="$glossterm.width"/>
669
670   &setup-language-variable;
671
672   <xsl:variable name="entries" select="glossentry"/>
673
674   <xsl:variable name="preamble"
675                 select="*[not(self::title
676                             or self::subtitle
677                             or self::glossentry)]"/>
678
679   <xsl:call-template name="glossdiv.titlepage"/>
680
681   <xsl:apply-templates select="$preamble"/>
682
683   <fo:list-block provisional-distance-between-starts="{$width}"
684                  provisional-label-separation="{$glossterm.separation}"
685                  xsl:use-attribute-sets="normal.para.spacing">
686     <xsl:choose>
687       <xsl:when test="$glossary.sort != 0">
688         <xsl:apply-templates select="$entries" mode="glossary.as.list">
689                                 <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
690         </xsl:apply-templates>
691       </xsl:when>
692       <xsl:otherwise>
693         <xsl:apply-templates select="$entries" mode="glossary.as.list"/>
694       </xsl:otherwise>
695     </xsl:choose>
696   </fo:list-block>
697 </xsl:template>
698
699 <!--
700 GlossEntry ::=
701   GlossTerm, Acronym?, Abbrev?,
702   (IndexTerm)*,
703   RevHistory?,
704   (GlossSee | GlossDef+)
705 -->
706
707 <xsl:template match="glossentry" mode="glossary.as.list">
708   <xsl:variable name="id">
709     <xsl:call-template name="object.id"/>
710   </xsl:variable>
711
712   <fo:list-item xsl:use-attribute-sets="glossentry.list.item.properties">
713     <xsl:call-template name="anchor">
714       <xsl:with-param name="conditional">
715         <xsl:choose>
716           <xsl:when test="$glossterm.auto.link != 0
717                           or $glossary.collection != ''">0</xsl:when>
718           <xsl:otherwise>1</xsl:otherwise>
719         </xsl:choose>
720       </xsl:with-param>
721     </xsl:call-template>
722
723     <fo:list-item-label end-indent="label-end()">
724       <fo:block xsl:use-attribute-sets="glossterm.list.properties">
725         <xsl:choose>
726           <xsl:when test="$glossentry.show.acronym = 'primary'">
727             <xsl:choose>
728               <xsl:when test="acronym|abbrev">
729                 <xsl:apply-templates select="acronym|abbrev" 
730                                      mode="glossary.as.list"/>
731                 <xsl:text> (</xsl:text>
732                 <xsl:apply-templates select="glossterm" 
733                                      mode="glossary.as.list"/>
734                 <xsl:text>)</xsl:text>
735               </xsl:when>
736               <xsl:otherwise>
737                 <xsl:apply-templates select="glossterm" 
738                                      mode="glossary.as.list"/>
739               </xsl:otherwise>
740             </xsl:choose>
741           </xsl:when>
742
743           <xsl:when test="$glossentry.show.acronym = 'yes'">
744             <xsl:apply-templates select="glossterm" mode="glossary.as.list"/>
745
746             <xsl:if test="acronym|abbrev">
747               <xsl:text> (</xsl:text>
748               <xsl:apply-templates select="acronym|abbrev" 
749                                    mode="glossary.as.list"/>
750               <xsl:text>)</xsl:text>
751             </xsl:if>
752           </xsl:when>
753
754           <xsl:otherwise>
755             <xsl:apply-templates select="glossterm" mode="glossary.as.list"/>
756           </xsl:otherwise>
757         </xsl:choose>
758         <xsl:apply-templates select="indexterm"/>
759       </fo:block>
760     </fo:list-item-label>
761
762     <fo:list-item-body start-indent="body-start()">
763       <fo:block xsl:use-attribute-sets="glossdef.list.properties">
764         <xsl:apply-templates select="glosssee|glossdef" mode="glossary.as.list"/>
765       </fo:block>
766     </fo:list-item-body>
767   </fo:list-item>
768 </xsl:template>
769
770 <xsl:template match="glossentry/glossterm" mode="glossary.as.list">
771   <xsl:variable name="id">
772     <xsl:call-template name="object.id"/>
773   </xsl:variable>
774   <fo:inline id="{$id}">
775     <xsl:apply-templates/>
776   </fo:inline>
777   <xsl:if test="following-sibling::glossterm">, </xsl:if>
778 </xsl:template>
779
780 <xsl:template match="glossentry/acronym" mode="glossary.as.list">
781   <xsl:apply-templates/>
782   <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
783 </xsl:template>
784
785 <xsl:template match="glossentry/abbrev" mode="glossary.as.list">
786   <xsl:apply-templates/>
787   <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
788 </xsl:template>
789
790 <xsl:template match="glossentry/revhistory" mode="glossary.as.list">
791 </xsl:template>
792
793 <xsl:template match="glossentry/glosssee" mode="glossary.as.list">
794   <xsl:variable name="otherterm" select="@otherterm"/>
795   <xsl:variable name="targets" select="key('id', $otherterm)"/>
796   <xsl:variable name="target" select="$targets[1]"/>
797   <xsl:variable name="xlink" select="@xlink:href"/>
798
799   <fo:block>
800     <xsl:variable name="template">
801       <xsl:call-template name="gentext.template">
802         <xsl:with-param name="context" select="'glossary'"/>
803         <xsl:with-param name="name" select="'see'"/>
804       </xsl:call-template>
805     </xsl:variable>
806     <xsl:variable name="title">
807       <xsl:choose>
808         <xsl:when test="$target">
809           <fo:basic-link internal-destination="{$otherterm}"
810                          xsl:use-attribute-sets="xref.properties">
811             <xsl:apply-templates select="$target" mode="xref-to"/>
812           </fo:basic-link>
813         </xsl:when>
814         <xsl:when test="$xlink">
815           <xsl:call-template name="simple.xlink">
816             <xsl:with-param name="content">
817               <xsl:apply-templates/>
818             </xsl:with-param>
819           </xsl:call-template>
820         </xsl:when>
821         <xsl:when test="$otherterm != '' and not($target)">
822           <xsl:message>
823             <xsl:text>Warning: glosssee @otherterm reference not found: </xsl:text>
824             <xsl:value-of select="$otherterm"/>
825           </xsl:message>
826           <xsl:apply-templates mode="glossary.as.list"/>
827         </xsl:when>
828         <xsl:otherwise>
829           <xsl:apply-templates mode="glossary.as.list"/>
830         </xsl:otherwise>
831       </xsl:choose>
832     </xsl:variable>
833     <xsl:call-template name="substitute-markup">
834       <xsl:with-param name="template" select="$template"/>
835       <xsl:with-param name="title" select="$title"/>
836     </xsl:call-template>
837   </fo:block>
838 </xsl:template>
839
840 <xsl:template match="glossentry/glossdef" mode="glossary.as.list">
841   <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"/>
842   <xsl:if test="glossseealso">
843     <fo:block>
844       <xsl:variable name="template">
845         <xsl:call-template name="gentext.template">
846           <xsl:with-param name="context" select="'glossary'"/>
847           <xsl:with-param name="name" select="'seealso'"/>
848         </xsl:call-template>
849       </xsl:variable>
850       <xsl:variable name="title">
851         <xsl:apply-templates select="glossseealso" mode="glossary.as.list"/>
852       </xsl:variable>
853       <xsl:call-template name="substitute-markup">
854         <xsl:with-param name="template" select="$template"/>
855         <xsl:with-param name="title" select="$title"/>
856       </xsl:call-template>
857     </fo:block>
858   </xsl:if>
859 </xsl:template>
860
861 <xsl:template match="glossentry/glossdef/para[1]|glossentry/glossdef/simpara[1]"
862               mode="glossary.as.list">
863   <fo:block>
864     <xsl:apply-templates/>
865   </fo:block>
866 </xsl:template>
867
868 <xsl:template match="glossseealso" mode="glossary.as.list">
869   <xsl:variable name="otherterm" select="@otherterm"/>
870   <xsl:variable name="targets" select="key('id', $otherterm)"/>
871   <xsl:variable name="target" select="$targets[1]"/>
872   <xsl:variable name="xlink" select="@xlink:href"/>
873
874   <xsl:choose>
875     <xsl:when test="$target">
876       <fo:basic-link internal-destination="{$otherterm}"
877                      xsl:use-attribute-sets="xref.properties">
878         <xsl:apply-templates select="$target" mode="xref-to"/>
879       </fo:basic-link>
880     </xsl:when>
881     <xsl:when test="$xlink">
882       <xsl:call-template name="simple.xlink">
883         <xsl:with-param name="content">
884           <xsl:apply-templates/>
885         </xsl:with-param>
886       </xsl:call-template>
887     </xsl:when>
888     <xsl:when test="$otherterm != '' and not($target)">
889       <xsl:message>
890         <xsl:text>Warning: glossseealso @otherterm reference not found: </xsl:text>
891         <xsl:value-of select="$otherterm"/>
892       </xsl:message>
893       <xsl:apply-templates mode="glossary.as.list"/>
894     </xsl:when>
895     <xsl:otherwise>
896       <xsl:apply-templates mode="glossary.as.list"/>
897     </xsl:otherwise>
898   </xsl:choose>
899
900   <xsl:choose>
901     <xsl:when test="position() = last()"/>
902     <xsl:otherwise>
903                 <xsl:call-template name="gentext.template">
904                   <xsl:with-param name="context" select="'glossary'"/>
905                   <xsl:with-param name="name" select="'seealso-separator'"/>
906                 </xsl:call-template>
907     </xsl:otherwise>
908   </xsl:choose>
909 </xsl:template>
910
911 <!-- ==================================================================== -->
912 <!-- Format glossary blocks -->
913
914 <xsl:template match="glossdiv" mode="glossary.as.blocks">
915   &setup-language-variable;
916   <xsl:variable name="entries" select="glossentry"/>
917   <xsl:variable name="preamble"
918                 select="*[not(self::title
919                             or self::subtitle
920                             or self::glossentry)]"/>
921
922   <xsl:call-template name="glossdiv.titlepage"/>
923
924   <xsl:apply-templates select="$preamble"/>
925
926   <xsl:choose>
927     <xsl:when test="$glossary.sort != 0">
928       <xsl:apply-templates select="$entries" mode="glossary.as.blocks">
929                   <xsl:sort lang="{$language}" select="normalize-space(translate(concat(@sortas, glossterm[not(parent::glossentry/@sortas) or parent::glossentry/@sortas = '']), &lowercase;, &uppercase;))"/>
930       </xsl:apply-templates>
931     </xsl:when>
932     <xsl:otherwise>
933       <xsl:apply-templates select="$entries" mode="glossary.as.blocks"/>
934     </xsl:otherwise>
935   </xsl:choose>
936 </xsl:template>
937
938 <!--
939 GlossEntry ::=
940   GlossTerm, Acronym?, Abbrev?,
941   (IndexTerm)*,
942   RevHistory?,
943   (GlossSee | GlossDef+)
944 -->
945
946 <xsl:template match="glossentry" mode="glossary.as.blocks">
947   <xsl:variable name="id">
948     <xsl:call-template name="object.id"/>
949   </xsl:variable>
950
951   <fo:block xsl:use-attribute-sets="glossterm.block.properties">
952     <xsl:call-template name="anchor">
953       <xsl:with-param name="conditional">
954         <xsl:choose>
955           <xsl:when test="$glossterm.auto.link != 0
956                           or $glossary.collection != ''">0</xsl:when>
957           <xsl:otherwise>1</xsl:otherwise>
958         </xsl:choose>
959       </xsl:with-param>
960     </xsl:call-template>
961
962     <xsl:choose>
963       <xsl:when test="$glossentry.show.acronym = 'primary'">
964         <xsl:choose>
965           <xsl:when test="acronym|abbrev">
966             <xsl:apply-templates select="acronym|abbrev" mode="glossary.as.blocks"/>
967             <xsl:text> (</xsl:text>
968             <xsl:apply-templates select="glossterm" mode="glossary.as.blocks"/>
969             <xsl:text>)</xsl:text>
970           </xsl:when>
971           <xsl:otherwise>
972             <xsl:apply-templates select="glossterm" mode="glossary.as.blocks"/>
973           </xsl:otherwise>
974         </xsl:choose>
975       </xsl:when>
976
977       <xsl:when test="$glossentry.show.acronym = 'yes'">
978         <xsl:apply-templates select="glossterm" mode="glossary.as.blocks"/>
979
980         <xsl:if test="acronym|abbrev">
981           <xsl:text> (</xsl:text>
982           <xsl:apply-templates select="acronym|abbrev" mode="glossary.as.blocks"/>
983           <xsl:text>)</xsl:text>
984         </xsl:if>
985       </xsl:when>
986
987       <xsl:otherwise>
988         <xsl:apply-templates select="glossterm" mode="glossary.as.blocks"/>
989       </xsl:otherwise>
990     </xsl:choose>
991
992     <xsl:apply-templates select="indexterm"/>
993   </fo:block>
994
995   <fo:block xsl:use-attribute-sets="glossdef.block.properties">
996     <xsl:apply-templates select="glosssee|glossdef" mode="glossary.as.blocks"/>
997   </fo:block>
998 </xsl:template>
999
1000 <xsl:template match="glossentry/glossterm" mode="glossary.as.blocks">
1001   <xsl:variable name="id">
1002     <xsl:call-template name="object.id"/>
1003   </xsl:variable>
1004   <fo:inline id="{$id}">
1005     <xsl:apply-templates/>
1006   </fo:inline>
1007   <xsl:if test="following-sibling::glossterm">, </xsl:if>
1008 </xsl:template>
1009
1010 <xsl:template match="glossentry/acronym" mode="glossary.as.blocks">
1011   <xsl:apply-templates/>
1012   <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
1013 </xsl:template>
1014
1015 <xsl:template match="glossentry/abbrev" mode="glossary.as.blocks">
1016   <xsl:apply-templates/>
1017   <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if>
1018 </xsl:template>
1019
1020 <xsl:template match="glossentry/glosssee" mode="glossary.as.blocks">
1021   <xsl:variable name="otherterm" select="@otherterm"/>
1022   <xsl:variable name="targets" select="key('id', $otherterm)"/>
1023   <xsl:variable name="target" select="$targets[1]"/>
1024   <xsl:variable name="xlink" select="@xlink:href"/>
1025
1026   <xsl:variable name="template">
1027     <xsl:call-template name="gentext.template">
1028       <xsl:with-param name="context" select="'glossary'"/>
1029       <xsl:with-param name="name" select="'see'"/>
1030     </xsl:call-template>
1031   </xsl:variable>
1032   <xsl:variable name="title">
1033     <xsl:choose>
1034       <xsl:when test="$target">
1035         <fo:basic-link internal-destination="{$otherterm}"
1036                        xsl:use-attribute-sets="xref.properties">
1037           <xsl:apply-templates select="$target" mode="xref-to"/>
1038         </fo:basic-link>
1039       </xsl:when>
1040       <xsl:when test="$xlink">
1041         <xsl:call-template name="simple.xlink">
1042           <xsl:with-param name="content">
1043             <xsl:apply-templates/>
1044           </xsl:with-param>
1045         </xsl:call-template>
1046       </xsl:when>
1047       <xsl:when test="$otherterm != '' and not($target)">
1048         <xsl:message>
1049           <xsl:text>Warning: glosssee @otherterm reference not found: </xsl:text>
1050           <xsl:value-of select="$otherterm"/>
1051         </xsl:message>
1052         <xsl:apply-templates mode="glossary.as.blocks"/>
1053       </xsl:when>
1054       <xsl:otherwise>
1055         <xsl:apply-templates mode="glossary.as.blocks"/>
1056       </xsl:otherwise>
1057     </xsl:choose>
1058   </xsl:variable>
1059   <xsl:call-template name="substitute-markup">
1060     <xsl:with-param name="template" select="$template"/>
1061     <xsl:with-param name="title" select="$title"/>
1062   </xsl:call-template>
1063 </xsl:template>
1064
1065 <xsl:template match="glossentry/glossdef" mode="glossary.as.blocks">
1066   <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"
1067                        mode="glossary.as.blocks"/>
1068   <xsl:if test="glossseealso">
1069     <fo:block>
1070       <xsl:variable name="template">
1071         <xsl:call-template name="gentext.template">
1072           <xsl:with-param name="context" select="'glossary'"/>
1073           <xsl:with-param name="name" select="'seealso'"/>
1074         </xsl:call-template>
1075       </xsl:variable>
1076       <xsl:variable name="title">
1077         <xsl:apply-templates select="glossseealso" mode="glossary.as.blocks"/>
1078       </xsl:variable>
1079       <xsl:call-template name="substitute-markup">
1080         <xsl:with-param name="template" select="$template"/>
1081         <xsl:with-param name="title" select="$title"/>
1082       </xsl:call-template>
1083     </fo:block>
1084   </xsl:if>
1085 </xsl:template>
1086
1087 <xsl:template match="glossentry/glossdef/para[1]|glossentry/glossdef/simpara[1]"
1088               mode="glossary.as.blocks">
1089   <fo:block>
1090     <xsl:apply-templates/>
1091   </fo:block>
1092 </xsl:template>
1093
1094 <!-- Handle any other glossdef content normally -->
1095 <xsl:template match="*" mode="glossary.as.blocks">
1096   <xsl:apply-templates select="." />
1097 </xsl:template>
1098
1099 <xsl:template match="glossseealso" mode="glossary.as.blocks">
1100   <xsl:variable name="otherterm" select="@otherterm"/>
1101   <xsl:variable name="targets" select="key('id', $otherterm)"/>
1102   <xsl:variable name="target" select="$targets[1]"/>
1103   <xsl:variable name="xlink" select="@xlink:href"/>
1104
1105   <xsl:choose>
1106     <xsl:when test="$target">
1107       <fo:basic-link internal-destination="{$otherterm}"
1108                      xsl:use-attribute-sets="xref.properties">
1109         <xsl:apply-templates select="$target" mode="xref-to"/>
1110       </fo:basic-link>
1111     </xsl:when>
1112     <xsl:when test="$xlink">
1113       <xsl:call-template name="simple.xlink">
1114         <xsl:with-param name="content">
1115           <xsl:apply-templates/>
1116         </xsl:with-param>
1117       </xsl:call-template>
1118     </xsl:when>
1119     <xsl:when test="$otherterm != '' and not($target)">
1120       <xsl:message>
1121         <xsl:text>Warning: glossseealso @otherterm reference not found: </xsl:text>
1122         <xsl:value-of select="$otherterm"/>
1123       </xsl:message>
1124       <xsl:apply-templates mode="glossary.as.blocks"/>
1125     </xsl:when>
1126     <xsl:otherwise>
1127       <xsl:apply-templates mode="glossary.as.blocks"/>
1128     </xsl:otherwise>
1129   </xsl:choose>
1130
1131   <xsl:choose>
1132     <xsl:when test="position() = last()"/>
1133     <xsl:otherwise>
1134                 <xsl:call-template name="gentext.template">
1135                   <xsl:with-param name="context" select="'glossary'"/>
1136                   <xsl:with-param name="name" select="'seealso-separator'"/>
1137                 </xsl:call-template>
1138     </xsl:otherwise>
1139   </xsl:choose>
1140 </xsl:template>
1141
1142 <!-- ==================================================================== -->
1143
1144 </xsl:stylesheet>