Imported Upstream version 1.79.0
[platform/upstream/docbook-xsl-stylesheets.git] / fo / lists.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                 version='1.0'>
5
6 <!-- ********************************************************************
7      $Id: lists.xsl 9999 2015-10-15 17:55:56Z bobstayton $
8      ********************************************************************
9
10      This file is part of the XSL DocBook Stylesheet distribution.
11      See ../README or http://docbook.sf.net/release/xsl/current/ for
12      copyright and other information.
13
14      ******************************************************************** -->
15
16 <!-- ==================================================================== -->
17
18 <xsl:template match="itemizedlist">
19   <xsl:variable name="id">
20     <xsl:call-template name="object.id"/>
21   </xsl:variable>
22
23   <xsl:variable name="keep.together">
24     <xsl:call-template name="pi.dbfo_keep-together"/>
25   </xsl:variable>
26
27   <xsl:variable name="pi-label-width">
28     <xsl:call-template name="pi.dbfo_label-width"/>
29   </xsl:variable>
30
31   <xsl:variable name="label-width">
32     <xsl:choose>
33       <xsl:when test="$pi-label-width = ''">
34         <xsl:value-of select="$itemizedlist.label.width"/>
35       </xsl:when>
36       <xsl:otherwise>
37         <xsl:value-of select="$pi-label-width"/>
38       </xsl:otherwise>
39     </xsl:choose>
40   </xsl:variable>
41
42   <xsl:if test="title">
43     <xsl:apply-templates select="title" mode="list.title.mode"/>
44   </xsl:if>
45
46   <!-- Preserve order of PIs and comments -->
47   <xsl:apply-templates 
48       select="*[not(self::listitem
49                 or self::title
50                 or self::titleabbrev)]
51               |comment()[not(preceding-sibling::listitem)]
52               |processing-instruction()[not(preceding-sibling::listitem)]"/>
53
54   <xsl:variable name="content">
55     <xsl:apply-templates 
56           select="listitem
57                   |comment()[preceding-sibling::listitem]
58                   |processing-instruction()[preceding-sibling::listitem]"/>
59   </xsl:variable>
60
61   <!-- nested lists don't add extra list-block spacing -->
62   <xsl:choose>
63     <xsl:when test="ancestor::listitem">
64       <fo:list-block id="{$id}" xsl:use-attribute-sets="itemizedlist.properties">
65         <xsl:attribute name="provisional-distance-between-starts">
66           <xsl:value-of select="$label-width"/>
67         </xsl:attribute>
68         <xsl:if test="$keep.together != ''">
69           <xsl:attribute name="keep-together.within-column"><xsl:value-of
70                           select="$keep.together"/></xsl:attribute>
71         </xsl:if>
72         <xsl:copy-of select="$content"/>
73       </fo:list-block>
74     </xsl:when>
75     <xsl:otherwise>
76       <fo:list-block id="{$id}" xsl:use-attribute-sets="list.block.spacing itemizedlist.properties">
77         <xsl:attribute name="provisional-distance-between-starts">
78           <xsl:value-of select="$label-width"/>
79         </xsl:attribute>
80         <xsl:if test="$keep.together != ''">
81           <xsl:attribute name="keep-together.within-column"><xsl:value-of
82                           select="$keep.together"/></xsl:attribute>
83         </xsl:if>
84         <xsl:copy-of select="$content"/>
85       </fo:list-block>
86     </xsl:otherwise>
87   </xsl:choose>
88
89 </xsl:template>
90
91 <xsl:template match="itemizedlist/title|orderedlist/title">
92   <!--nop-->
93 </xsl:template>
94
95 <xsl:template match="variablelist/title" mode="vl.as.list">
96   <!--nop-->
97 </xsl:template>
98
99 <xsl:template match="variablelist/title" mode="vl.as.blocks">
100   <!--nop-->
101 </xsl:template>
102
103 <xsl:template match="itemizedlist/titleabbrev|orderedlist/titleabbrev">
104   <!--nop-->
105 </xsl:template>
106
107 <xsl:template match="procedure/titleabbrev">
108   <!--nop-->
109 </xsl:template>
110
111 <xsl:template match="variablelist/titleabbrev" mode="vl.as.list">
112   <!--nop-->
113 </xsl:template>
114
115 <xsl:template match="variablelist/titleabbrev" mode="vl.as.blocks">
116   <!--nop-->
117 </xsl:template>
118
119 <xsl:template match="itemizedlist/listitem">
120   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
121
122   <xsl:variable name="keep.together">
123     <xsl:call-template name="pi.dbfo_keep-together"/>
124   </xsl:variable>
125
126   <xsl:variable name="item.contents">
127     <fo:list-item-label end-indent="label-end()" xsl:use-attribute-sets="itemizedlist.label.properties">
128       <fo:block>
129         <xsl:call-template name="itemizedlist.label.markup">
130           <xsl:with-param name="itemsymbol">
131             <xsl:call-template name="list.itemsymbol">
132               <xsl:with-param name="node" select="parent::itemizedlist"/>
133             </xsl:call-template>
134           </xsl:with-param>
135         </xsl:call-template>
136       </fo:block>
137     </fo:list-item-label>
138     <fo:list-item-body start-indent="body-start()">
139       <fo:block>
140         <xsl:apply-templates/>
141       </fo:block>
142     </fo:list-item-body>
143   </xsl:variable>
144
145   <xsl:choose>
146     <xsl:when test="parent::*/@spacing = 'compact'">
147       <fo:list-item id="{$id}" xsl:use-attribute-sets="compact.list.item.spacing">
148         <xsl:if test="$keep.together != ''">
149           <xsl:attribute name="keep-together.within-column"><xsl:value-of
150                           select="$keep.together"/></xsl:attribute>
151         </xsl:if>
152         <xsl:copy-of select="$item.contents"/>
153       </fo:list-item>
154     </xsl:when>
155     <xsl:otherwise>
156       <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
157         <xsl:if test="$keep.together != ''">
158           <xsl:attribute name="keep-together.within-column"><xsl:value-of
159                           select="$keep.together"/></xsl:attribute>
160         </xsl:if>
161         <xsl:copy-of select="$item.contents"/>
162       </fo:list-item>
163     </xsl:otherwise>
164   </xsl:choose>
165 </xsl:template>
166
167 <xsl:template name="itemizedlist.label.markup">
168   <xsl:param name="itemsymbol" select="'disc'"/>
169
170   <xsl:choose>
171     <xsl:when test="$itemsymbol='none'"></xsl:when>
172     <xsl:when test="$itemsymbol='disc'">&#x2022;</xsl:when>
173     <xsl:when test="$itemsymbol='bullet'">&#x2022;</xsl:when>
174     <xsl:when test="$itemsymbol='endash'">&#x2013;</xsl:when>
175     <xsl:when test="$itemsymbol='emdash'">&#x2014;</xsl:when>
176     <!-- Some of these may work in your XSL-FO processor and fonts -->
177     <!--
178     <xsl:when test="$itemsymbol='square'">&#x25A0;</xsl:when>
179     <xsl:when test="$itemsymbol='box'">&#x25A0;</xsl:when>
180     <xsl:when test="$itemsymbol='smallblacksquare'">&#x25AA;</xsl:when>
181     <xsl:when test="$itemsymbol='circle'">&#x25CB;</xsl:when>
182     <xsl:when test="$itemsymbol='opencircle'">&#x25CB;</xsl:when>
183     <xsl:when test="$itemsymbol='whitesquare'">&#x25A1;</xsl:when>
184     <xsl:when test="$itemsymbol='smallwhitesquare'">&#x25AB;</xsl:when>
185     <xsl:when test="$itemsymbol='round'">&#x25CF;</xsl:when>
186     <xsl:when test="$itemsymbol='blackcircle'">&#x25CF;</xsl:when>
187     <xsl:when test="$itemsymbol='whitebullet'">&#x25E6;</xsl:when>
188     <xsl:when test="$itemsymbol='triangle'">&#x2023;</xsl:when>
189     <xsl:when test="$itemsymbol='point'">&#x203A;</xsl:when>
190     <xsl:when test="$itemsymbol='hand'"><fo:inline 
191                          font-family="Wingdings 2">A</fo:inline></xsl:when>
192     -->
193     <xsl:otherwise>&#x2022;</xsl:otherwise>
194   </xsl:choose>
195 </xsl:template>
196
197 <xsl:template match="orderedlist">
198   <xsl:variable name="id">
199     <xsl:call-template name="object.id"/>
200   </xsl:variable>
201
202   <xsl:variable name="pi-label-width">
203     <xsl:call-template name="pi.dbfo_label-width"/>
204   </xsl:variable>
205
206   <xsl:variable name="label-width">
207     <xsl:choose>
208       <xsl:when test="$pi-label-width = ''">
209         <xsl:value-of select="$orderedlist.label.width"/>
210       </xsl:when>
211       <xsl:otherwise>
212         <xsl:value-of select="$pi-label-width"/>
213       </xsl:otherwise>
214     </xsl:choose>
215   </xsl:variable>
216
217   <xsl:variable name="keep.together">
218     <xsl:call-template name="pi.dbfo_keep-together"/>
219   </xsl:variable>
220
221   <xsl:if test="title">
222     <xsl:apply-templates select="title" mode="list.title.mode"/>
223   </xsl:if>
224
225   <!-- Preserve order of PIs and comments -->
226   <xsl:apply-templates 
227       select="*[not(self::listitem
228                 or self::title
229                 or self::titleabbrev)]
230               |comment()[not(preceding-sibling::listitem)]
231               |processing-instruction()[not(preceding-sibling::listitem)]"/>
232
233   <xsl:variable name="content">
234     <xsl:apply-templates 
235           select="listitem
236                   |comment()[preceding-sibling::listitem]
237                   |processing-instruction()[preceding-sibling::listitem]"/>
238   </xsl:variable>
239
240   <!-- nested lists don't add extra list-block spacing -->
241   <xsl:choose>
242     <xsl:when test="ancestor::listitem">
243       <fo:list-block id="{$id}" xsl:use-attribute-sets="orderedlist.properties">
244         <xsl:attribute name="provisional-distance-between-starts">
245           <xsl:value-of select="$label-width"/>
246         </xsl:attribute>
247         <xsl:if test="$keep.together != ''">
248           <xsl:attribute name="keep-together.within-column"><xsl:value-of
249                           select="$keep.together"/></xsl:attribute>
250         </xsl:if>
251         <xsl:copy-of select="$content"/>
252       </fo:list-block>
253     </xsl:when>
254     <xsl:otherwise>
255       <fo:list-block id="{$id}" xsl:use-attribute-sets="list.block.spacing orderedlist.properties">
256         <xsl:attribute name="provisional-distance-between-starts">
257           <xsl:value-of select="$label-width"/>
258         </xsl:attribute>
259         <xsl:if test="$keep.together != ''">
260           <xsl:attribute name="keep-together.within-column"><xsl:value-of
261                           select="$keep.together"/></xsl:attribute>
262         </xsl:if>
263         <xsl:copy-of select="$content"/>
264       </fo:list-block>
265     </xsl:otherwise>
266   </xsl:choose>
267 </xsl:template>
268
269 <xsl:template match="orderedlist/listitem">
270   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
271
272   <xsl:variable name="keep.together">
273     <xsl:call-template name="pi.dbfo_keep-together"/>
274   </xsl:variable>
275
276   <xsl:variable name="item.contents">
277     <fo:list-item-label end-indent="label-end()" xsl:use-attribute-sets="orderedlist.label.properties">
278       <fo:block>
279         <xsl:apply-templates select="." mode="item-number"/>
280       </fo:block>
281     </fo:list-item-label>
282     <fo:list-item-body start-indent="body-start()">
283       <fo:block>
284         <xsl:apply-templates/>
285       </fo:block>
286     </fo:list-item-body>
287   </xsl:variable>
288
289   <xsl:choose>
290     <xsl:when test="parent::*/@spacing = 'compact'">
291       <fo:list-item id="{$id}" xsl:use-attribute-sets="compact.list.item.spacing">
292         <xsl:if test="$keep.together != ''">
293           <xsl:attribute name="keep-together.within-column"><xsl:value-of
294                           select="$keep.together"/></xsl:attribute>
295         </xsl:if>
296         <xsl:copy-of select="$item.contents"/>
297       </fo:list-item>
298     </xsl:when>
299     <xsl:otherwise>
300       <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
301         <xsl:if test="$keep.together != ''">
302           <xsl:attribute name="keep-together.within-column"><xsl:value-of
303                           select="$keep.together"/></xsl:attribute>
304         </xsl:if>
305         <xsl:copy-of select="$item.contents"/>
306       </fo:list-item>
307     </xsl:otherwise>
308   </xsl:choose>
309 </xsl:template>
310
311 <xsl:template match="listitem/*[1][local-name()='para' or 
312                                    local-name()='simpara' or 
313                                    local-name()='formalpara']
314                      |glossdef/*[1][local-name()='para' or 
315                                    local-name()='simpara' or 
316                                    local-name()='formalpara']
317                      |step/*[1][local-name()='para' or 
318                                    local-name()='simpara' or 
319                                    local-name()='formalpara']
320                      |callout/*[1][local-name()='para' or 
321                                    local-name()='simpara' or 
322                                    local-name()='formalpara']"
323               priority="2">
324   <fo:block xsl:use-attribute-sets="para.properties">
325     <xsl:call-template name="anchor"/>
326     <xsl:apply-templates/>
327   </fo:block>
328 </xsl:template>
329
330 <xsl:template match="variablelist">
331   <xsl:variable name="presentation">
332     <xsl:call-template name="pi.dbfo_list-presentation"/>
333   </xsl:variable>
334
335   <xsl:choose>
336     <xsl:when test="$presentation = 'list'">
337       <xsl:apply-templates select="." mode="vl.as.list"/>
338     </xsl:when>
339     <xsl:when test="$presentation = 'blocks'">
340       <xsl:apply-templates select="." mode="vl.as.blocks"/>
341     </xsl:when>
342     <xsl:when test="$variablelist.as.blocks != 0">
343       <xsl:apply-templates select="." mode="vl.as.blocks"/>
344     </xsl:when>
345     <xsl:otherwise>
346       <xsl:apply-templates select="." mode="vl.as.list"/>
347     </xsl:otherwise>
348   </xsl:choose>
349 </xsl:template>
350
351 <xsl:template match="variablelist" mode="vl.as.list">
352   <xsl:variable name="id">
353     <xsl:call-template name="object.id"/>
354   </xsl:variable>
355
356   <xsl:variable name="keep.together">
357     <xsl:call-template name="pi.dbfo_keep-together"/>
358   </xsl:variable>
359
360   <xsl:variable name="term-width">
361     <xsl:call-template name="pi.dbfo_term-width"/>
362   </xsl:variable>
363
364   <xsl:variable name="termlength">
365     <xsl:choose>
366       <xsl:when test="$term-width != ''">
367         <xsl:value-of select="$term-width"/>
368       </xsl:when>
369       <xsl:when test="@termlength">
370         <xsl:variable name="termlength.is.number">
371           <xsl:value-of select="@termlength + 0"/>
372         </xsl:variable>
373         <xsl:choose>
374           <xsl:when test="string($termlength.is.number) = 'NaN'">
375             <!-- if the term length isn't just a number, assume it's a measurement -->
376             <xsl:value-of select="@termlength"/>
377           </xsl:when>
378           <xsl:otherwise>
379             <xsl:value-of select="@termlength"/>
380             <xsl:text>em * 0.60</xsl:text>
381           </xsl:otherwise>
382         </xsl:choose>
383       </xsl:when>
384       <xsl:otherwise>
385         <xsl:call-template name="longest.term">
386           <xsl:with-param name="terms" select="varlistentry/term"/>
387           <xsl:with-param name="maxlength" select="$variablelist.max.termlength"/>
388         </xsl:call-template>
389         <xsl:text>em * 0.60</xsl:text>
390       </xsl:otherwise>
391     </xsl:choose>
392   </xsl:variable>
393
394 <!--
395   <xsl:message>
396     <xsl:text>term width: </xsl:text>
397     <xsl:value-of select="$termlength"/>
398   </xsl:message>
399 -->
400
401   <xsl:variable name="label-separation">1em</xsl:variable>
402   <xsl:variable name="distance-between-starts">
403     <xsl:value-of select="$termlength"/>
404     <xsl:text>+</xsl:text>
405     <xsl:value-of select="$label-separation"/>
406   </xsl:variable>
407
408   <xsl:if test="title">
409     <xsl:apply-templates select="title" mode="list.title.mode"/>
410   </xsl:if>
411
412   <!-- Preserve order of PIs and comments -->
413   <xsl:apply-templates 
414     select="*[not(self::varlistentry
415               or self::title
416               or self::titleabbrev)]
417             |comment()[not(preceding-sibling::varlistentry)]
418             |processing-instruction()[not(preceding-sibling::varlistentry)]"/>
419
420   <xsl:variable name="content">
421     <xsl:apply-templates mode="vl.as.list"
422       select="varlistentry
423               |comment()[preceding-sibling::varlistentry]
424               |processing-instruction()[preceding-sibling::varlistentry]"/>
425   </xsl:variable>
426
427   <!-- nested lists don't add extra list-block spacing -->
428   <xsl:choose>
429     <xsl:when test="ancestor::listitem">
430       <fo:list-block id="{$id}"
431                      provisional-distance-between-starts=
432                         "{$distance-between-starts}"
433                      provisional-label-separation="{$label-separation}">
434         <xsl:if test="$keep.together != ''">
435           <xsl:attribute name="keep-together.within-column"><xsl:value-of
436                           select="$keep.together"/></xsl:attribute>
437         </xsl:if>
438         <xsl:copy-of select="$content"/>
439       </fo:list-block>
440     </xsl:when>
441     <xsl:otherwise>
442       <fo:list-block id="{$id}"
443                      provisional-distance-between-starts=
444                         "{$distance-between-starts}"
445                      provisional-label-separation="{$label-separation}"
446                      xsl:use-attribute-sets="list.block.spacing">
447         <xsl:if test="$keep.together != ''">
448           <xsl:attribute name="keep-together.within-column"><xsl:value-of
449                           select="$keep.together"/></xsl:attribute>
450         </xsl:if>
451         <xsl:copy-of select="$content"/>
452       </fo:list-block>
453     </xsl:otherwise>
454   </xsl:choose>
455 </xsl:template>
456
457 <xsl:template name="longest.term">
458   <xsl:param name="longest" select="0"/>
459   <xsl:param name="terms" select="."/>
460   <xsl:param name="maxlength" select="-1"/>
461
462   <!-- Process out any indexterms in the term -->
463   <xsl:variable name="term.text">
464     <xsl:apply-templates select="$terms[1]"/>
465   </xsl:variable>
466
467   <xsl:choose>
468     <xsl:when test="$longest &gt; $maxlength and $maxlength &gt; 0">
469       <xsl:value-of select="$maxlength"/>
470     </xsl:when>
471     <xsl:when test="not($terms)">
472       <xsl:value-of select="$longest"/>
473     </xsl:when>
474     <xsl:when test="string-length($term.text) &gt; $longest">
475       <xsl:call-template name="longest.term">
476         <xsl:with-param name="longest" 
477             select="string-length($term.text)"/>
478         <xsl:with-param name="maxlength" select="$maxlength"/>
479         <xsl:with-param name="terms" select="$terms[position() &gt; 1]"/>
480       </xsl:call-template>
481     </xsl:when>
482     <xsl:otherwise>
483       <xsl:call-template name="longest.term">
484         <xsl:with-param name="longest" select="$longest"/>
485         <xsl:with-param name="maxlength" select="$maxlength"/>
486         <xsl:with-param name="terms" select="$terms[position() &gt; 1]"/>
487       </xsl:call-template>
488     </xsl:otherwise>
489   </xsl:choose>
490 </xsl:template>
491
492 <xsl:template match="varlistentry" mode="vl.as.list">
493   <xsl:variable name="id">
494     <xsl:call-template name="object.id"/>
495   </xsl:variable>
496
497   <xsl:variable name="keep.together">
498     <xsl:call-template name="pi.dbfo_keep-together"/>
499   </xsl:variable>
500
501   <xsl:variable name="item.contents">
502     <fo:list-item-label end-indent="label-end()" text-align="start">
503       <fo:block xsl:use-attribute-sets="variablelist.term.properties">
504         <xsl:apply-templates select="term"/>
505       </fo:block>
506     </fo:list-item-label>
507     <fo:list-item-body start-indent="body-start()">
508       <fo:block>
509         <xsl:apply-templates select="listitem"/>
510       </fo:block>
511     </fo:list-item-body>
512   </xsl:variable>
513
514   <xsl:choose>
515     <xsl:when test="parent::*/@spacing = 'compact'">
516       <fo:list-item id="{$id}"
517           xsl:use-attribute-sets="compact.list.item.spacing">
518         <xsl:if test="$keep.together != ''">
519           <xsl:attribute name="keep-together.within-column"><xsl:value-of
520                           select="$keep.together"/></xsl:attribute>
521         </xsl:if>
522         <xsl:copy-of select="$item.contents"/>
523       </fo:list-item>
524     </xsl:when>
525     <xsl:otherwise>
526       <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
527         <xsl:if test="$keep.together != ''">
528           <xsl:attribute name="keep-together.within-column"><xsl:value-of
529                           select="$keep.together"/></xsl:attribute>
530         </xsl:if>
531         <xsl:copy-of select="$item.contents"/>
532       </fo:list-item>
533     </xsl:otherwise>
534   </xsl:choose>
535 </xsl:template>
536
537
538 <xsl:template match="variablelist" mode="vl.as.blocks">
539   <xsl:variable name="id">
540     <xsl:call-template name="object.id"/>
541   </xsl:variable>
542
543   <!-- termlength is irrelevant -->
544
545   <xsl:if test="title">
546     <xsl:apply-templates select="title" mode="list.title.mode"/>
547   </xsl:if>
548
549   <!-- Preserve order of PIs and comments -->
550   <xsl:apply-templates 
551     select="*[not(self::varlistentry
552               or self::title
553               or self::titleabbrev)]
554             |comment()[not(preceding-sibling::varlistentry)]
555             |processing-instruction()[not(preceding-sibling::varlistentry)]"/>
556
557   <xsl:variable name="content">
558     <xsl:apply-templates mode="vl.as.blocks"
559       select="varlistentry
560               |comment()[preceding-sibling::varlistentry]
561               |processing-instruction()[preceding-sibling::varlistentry]"/>
562   </xsl:variable>
563
564   <!-- nested lists don't add extra list-block spacing -->
565   <xsl:choose>
566     <xsl:when test="ancestor::listitem">
567       <fo:block id="{$id}">
568         <xsl:copy-of select="$content"/>
569       </fo:block>
570     </xsl:when>
571     <xsl:otherwise>
572       <fo:block id="{$id}" xsl:use-attribute-sets="list.block.spacing">
573         <xsl:copy-of select="$content"/>
574       </fo:block>
575     </xsl:otherwise>
576   </xsl:choose>
577 </xsl:template>
578
579 <xsl:template match="varlistentry" mode="vl.as.blocks">
580   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
581
582   <fo:block id="{$id}" xsl:use-attribute-sets="variablelist.term.properties
583                                                list.item.spacing"  
584       keep-together.within-column="always" 
585       keep-with-next.within-column="always">
586     <xsl:apply-templates select="term"/>
587   </fo:block>
588
589   <fo:block>
590     <xsl:attribute name="margin-{$direction.align.start}">0.25in</xsl:attribute>
591     <xsl:apply-templates select="listitem"/>
592   </fo:block>
593 </xsl:template>
594
595 <xsl:template match="varlistentry/term">
596   <fo:inline>
597     <xsl:call-template name="anchor"/>
598     <xsl:call-template name="simple.xlink">
599       <xsl:with-param name="content">
600         <xsl:apply-templates/>
601       </xsl:with-param>
602     </xsl:call-template>
603   </fo:inline>
604   <xsl:choose>
605     <xsl:when test="not(following-sibling::term)"/> <!-- do nothing -->
606     <xsl:otherwise>
607       <!-- * if we have multiple terms in the same varlistentry, generate -->
608       <!-- * a separator (", " by default) and/or an additional line -->
609       <!-- * break after each one except the last -->
610       <fo:inline><xsl:value-of select="$variablelist.term.separator"/></fo:inline>
611       <xsl:if test="not($variablelist.term.break.after = '0')">
612         <fo:block/>
613       </xsl:if>
614     </xsl:otherwise>
615   </xsl:choose>
616 </xsl:template>
617
618 <xsl:template match="varlistentry/listitem">
619   <xsl:apply-templates/>
620 </xsl:template>
621
622 <!-- ==================================================================== -->
623
624 <xsl:template match="title" mode="list.title.mode">
625   <xsl:call-template name="formal.object.heading">
626     <xsl:with-param name="object" select=".."/>
627   </xsl:call-template>
628 </xsl:template>
629
630 <!-- ==================================================================== -->
631
632 <xsl:template match="simplelist|simplelist[@type='vert']">
633   <!-- with no type specified, the default is 'vert' -->
634
635   <xsl:variable name="id">
636     <xsl:call-template name="object.id"/>
637   </xsl:variable>
638
639   <xsl:variable name="explicit.table.width">
640     <xsl:call-template name="dbfo-attribute">
641       <xsl:with-param name="pis"
642                       select="processing-instruction('dbfo')"/>
643       <xsl:with-param name="attribute" select="'list-width'"/>
644     </xsl:call-template>
645   </xsl:variable>
646
647   <xsl:variable name="table.width">
648     <xsl:choose>
649       <xsl:when test="$explicit.table.width != ''">
650         <xsl:value-of select="$explicit.table.width"/>
651       </xsl:when>
652       <xsl:when test="$default.table.width = ''">
653         <xsl:text>100%</xsl:text>
654       </xsl:when>
655       <xsl:otherwise>
656         <xsl:value-of select="$default.table.width"/>
657       </xsl:otherwise>
658     </xsl:choose>
659   </xsl:variable>
660
661   <fo:table id="{$id}" xsl:use-attribute-sets="normal.para.spacing">
662
663     <xsl:choose>
664       <xsl:when test="$axf.extensions != 0 or $xep.extensions != 0">
665         <xsl:attribute name="table-layout">auto</xsl:attribute>
666         <xsl:if test="$explicit.table.width != ''">
667           <xsl:attribute name="width"><xsl:value-of 
668           select="$explicit.table.width"/></xsl:attribute>
669         </xsl:if>
670       </xsl:when>
671       <xsl:otherwise>
672         <xsl:attribute name="table-layout">fixed</xsl:attribute>
673         <xsl:attribute name="width"><xsl:value-of 
674                                       select="$table.width"/></xsl:attribute>
675       </xsl:otherwise>
676     </xsl:choose>
677
678     <xsl:call-template name="simplelist.table.columns">
679       <xsl:with-param name="cols">
680         <xsl:choose>
681           <xsl:when test="@columns">
682             <xsl:value-of select="@columns"/>
683           </xsl:when>
684           <xsl:otherwise>1</xsl:otherwise>
685         </xsl:choose>
686       </xsl:with-param>
687     </xsl:call-template>
688     <fo:table-body start-indent="0pt" end-indent="0pt">
689       <xsl:call-template name="simplelist.vert">
690         <xsl:with-param name="cols">
691           <xsl:choose>
692             <xsl:when test="@columns">
693               <xsl:value-of select="@columns"/>
694             </xsl:when>
695             <xsl:otherwise>1</xsl:otherwise>
696           </xsl:choose>
697         </xsl:with-param>
698       </xsl:call-template>
699     </fo:table-body>
700   </fo:table>
701 </xsl:template>
702
703 <xsl:template match="simplelist[@type='inline']">
704   <!-- if dbchoice PI exists, use that to determine the choice separator -->
705   <!-- (that is, equivalent of "and" or "or" in current locale), or literal -->
706   <!-- value of "choice" otherwise -->
707   <xsl:variable name="id">
708     <xsl:call-template name="object.id"/>
709   </xsl:variable>
710
711   <fo:inline id="{$id}"><xsl:variable name="localized-choice-separator">
712     <xsl:choose>
713       <xsl:when test="processing-instruction('dbchoice')">
714         <xsl:call-template name="select.choice.separator"/>
715       </xsl:when>
716       <xsl:otherwise>
717         <!-- empty -->
718       </xsl:otherwise>
719     </xsl:choose>
720   </xsl:variable>
721
722   <xsl:for-each select="member">
723     <xsl:apply-templates/>
724     <xsl:choose>
725       <xsl:when test="position() = last()"/> <!-- do nothing -->
726       <xsl:otherwise>
727         <xsl:text>, </xsl:text>
728         <xsl:if test="position() = last() - 1">
729           <xsl:if test="$localized-choice-separator != ''">
730             <xsl:value-of select="$localized-choice-separator"/>
731             <xsl:text> </xsl:text>
732           </xsl:if>
733         </xsl:if>
734       </xsl:otherwise>
735     </xsl:choose>
736   </xsl:for-each></fo:inline>
737 </xsl:template>
738
739 <xsl:template match="simplelist[@type='horiz']">
740
741   <xsl:variable name="id">
742     <xsl:call-template name="object.id"/>
743   </xsl:variable>
744
745   <xsl:variable name="explicit.table.width">
746     <xsl:call-template name="pi.dbfo_list-width"/>
747   </xsl:variable>
748
749   <xsl:variable name="table.width">
750     <xsl:choose>
751       <xsl:when test="$explicit.table.width != ''">
752         <xsl:value-of select="$explicit.table.width"/>
753       </xsl:when>
754       <xsl:when test="$default.table.width = ''">
755         <xsl:text>100%</xsl:text>
756       </xsl:when>
757       <xsl:otherwise>
758         <xsl:value-of select="$default.table.width"/>
759       </xsl:otherwise>
760     </xsl:choose>
761   </xsl:variable>
762
763   <fo:table id="{$id}" xsl:use-attribute-sets="normal.para.spacing">
764     <xsl:choose>
765       <xsl:when test="$axf.extensions != 0 or $xep.extensions != 0">
766         <xsl:attribute name="table-layout">auto</xsl:attribute>
767         <xsl:if test="$explicit.table.width != ''">
768           <xsl:attribute name="width"><xsl:value-of 
769                              select="$explicit.table.width"/></xsl:attribute>
770         </xsl:if>
771       </xsl:when>
772       <xsl:otherwise>
773         <xsl:attribute name="table-layout">fixed</xsl:attribute>
774         <xsl:attribute name="width"><xsl:value-of 
775                                       select="$table.width"/></xsl:attribute>
776       </xsl:otherwise>
777     </xsl:choose>
778     <xsl:call-template name="simplelist.table.columns">
779       <xsl:with-param name="cols">
780         <xsl:choose>
781           <xsl:when test="@columns">
782             <xsl:value-of select="@columns"/>
783           </xsl:when>
784           <xsl:otherwise>1</xsl:otherwise>
785         </xsl:choose>
786       </xsl:with-param>
787     </xsl:call-template>
788     <fo:table-body start-indent="0pt" end-indent="0pt">
789       <xsl:call-template name="simplelist.horiz">
790         <xsl:with-param name="cols">
791           <xsl:choose>
792             <xsl:when test="@columns">
793               <xsl:value-of select="@columns"/>
794             </xsl:when>
795             <xsl:otherwise>1</xsl:otherwise>
796           </xsl:choose>
797         </xsl:with-param>
798       </xsl:call-template>
799     </fo:table-body>
800   </fo:table>
801 </xsl:template>
802
803 <xsl:template name="simplelist.table.columns">
804   <xsl:param name="cols" select="1"/>
805   <xsl:param name="curcol" select="1"/>
806   <fo:table-column column-number="{$curcol}"
807                    column-width="proportional-column-width(1)"/>
808   <xsl:if test="$curcol &lt; $cols">
809     <xsl:call-template name="simplelist.table.columns">
810       <xsl:with-param name="cols" select="$cols"/>
811       <xsl:with-param name="curcol" select="$curcol + 1"/>
812     </xsl:call-template>
813   </xsl:if>
814 </xsl:template>
815
816 <xsl:template name="simplelist.horiz">
817   <xsl:param name="cols">1</xsl:param>
818   <xsl:param name="cell">1</xsl:param>
819   <xsl:param name="members" select="./member"/>
820
821   <xsl:if test="$cell &lt;= count($members)">
822     <fo:table-row>
823       <xsl:call-template name="simplelist.horiz.row">
824         <xsl:with-param name="cols" select="$cols"/>
825         <xsl:with-param name="cell" select="$cell"/>
826         <xsl:with-param name="members" select="$members"/>
827       </xsl:call-template>
828    </fo:table-row>
829     <xsl:call-template name="simplelist.horiz">
830       <xsl:with-param name="cols" select="$cols"/>
831       <xsl:with-param name="cell" select="$cell + $cols"/>
832       <xsl:with-param name="members" select="$members"/>
833     </xsl:call-template>
834   </xsl:if>
835 </xsl:template>
836
837 <xsl:template name="simplelist.horiz.row">
838   <xsl:param name="cols">1</xsl:param>
839   <xsl:param name="cell">1</xsl:param>
840   <xsl:param name="members" select="./member"/>
841   <xsl:param name="curcol">1</xsl:param>
842
843   <xsl:if test="$curcol &lt;= $cols">
844     <fo:table-cell>
845       <fo:block>
846         <xsl:if test="$members[position()=$cell]">
847           <xsl:apply-templates select="$members[position()=$cell]"/>
848         </xsl:if>
849       </fo:block>
850     </fo:table-cell>
851     <xsl:call-template name="simplelist.horiz.row">
852       <xsl:with-param name="cols" select="$cols"/>
853       <xsl:with-param name="cell" select="$cell+1"/>
854       <xsl:with-param name="members" select="$members"/>
855       <xsl:with-param name="curcol" select="$curcol+1"/>
856     </xsl:call-template>
857   </xsl:if>
858 </xsl:template>
859
860 <xsl:template name="simplelist.vert">
861   <xsl:param name="cols">1</xsl:param>
862   <xsl:param name="cell">1</xsl:param>
863   <xsl:param name="members" select="./member"/>
864   <xsl:param name="rows"
865              select="floor((count($members)+$cols - 1) div $cols)"/>
866
867   <xsl:if test="$cell &lt;= $rows">
868     <fo:table-row>
869       <xsl:call-template name="simplelist.vert.row">
870         <xsl:with-param name="cols" select="$cols"/>
871         <xsl:with-param name="rows" select="$rows"/>
872         <xsl:with-param name="cell" select="$cell"/>
873         <xsl:with-param name="members" select="$members"/>
874       </xsl:call-template>
875    </fo:table-row>
876     <xsl:call-template name="simplelist.vert">
877       <xsl:with-param name="cols" select="$cols"/>
878       <xsl:with-param name="cell" select="$cell+1"/>
879       <xsl:with-param name="members" select="$members"/>
880       <xsl:with-param name="rows" select="$rows"/>
881     </xsl:call-template>
882   </xsl:if>
883 </xsl:template>
884
885 <xsl:template name="simplelist.vert.row">
886   <xsl:param name="cols">1</xsl:param>
887   <xsl:param name="rows">1</xsl:param>
888   <xsl:param name="cell">1</xsl:param>
889   <xsl:param name="members" select="./member"/>
890   <xsl:param name="curcol">1</xsl:param>
891
892   <xsl:if test="$curcol &lt;= $cols">
893     <fo:table-cell>
894       <fo:block>
895         <xsl:if test="$members[position()=$cell]">
896           <xsl:apply-templates select="$members[position()=$cell]"/>
897         </xsl:if>
898       </fo:block>
899     </fo:table-cell>
900     <xsl:call-template name="simplelist.vert.row">
901       <xsl:with-param name="cols" select="$cols"/>
902       <xsl:with-param name="rows" select="$rows"/>
903       <xsl:with-param name="cell" select="$cell+$rows"/>
904       <xsl:with-param name="members" select="$members"/>
905       <xsl:with-param name="curcol" select="$curcol+1"/>
906     </xsl:call-template>
907   </xsl:if>
908 </xsl:template>
909
910 <xsl:template match="member">
911   <xsl:call-template name="simple.xlink">
912     <xsl:with-param name="content">
913       <xsl:apply-templates/>
914     </xsl:with-param>
915   </xsl:call-template>
916 </xsl:template>
917
918 <!-- ==================================================================== -->
919
920 <xsl:template match="procedure">
921   <xsl:variable name="id">
922     <xsl:call-template name="object.id"/>
923   </xsl:variable>
924
925   <xsl:variable name="param.placement"
926                 select="substring-after(normalize-space($formal.title.placement),
927                                         concat(local-name(.), ' '))"/>
928
929   <xsl:variable name="placement">
930     <xsl:choose>
931       <xsl:when test="contains($param.placement, ' ')">
932         <xsl:value-of select="substring-before($param.placement, ' ')"/>
933       </xsl:when>
934       <xsl:when test="$param.placement = ''">before</xsl:when>
935       <xsl:otherwise>
936         <xsl:value-of select="$param.placement"/>
937       </xsl:otherwise>
938     </xsl:choose>
939   </xsl:variable>
940
941   <!-- Preserve order of PIs and comments -->
942   <xsl:variable name="preamble"
943         select="*[not(self::step
944                   or self::title
945                   or self::titleabbrev)]
946                 |comment()[not(preceding-sibling::step)]
947                 |processing-instruction()[not(preceding-sibling::step)]"/>
948
949   <xsl:variable name="steps" 
950                 select="step
951                         |comment()[preceding-sibling::step]
952                         |processing-instruction()[preceding-sibling::step]"/>
953
954   <fo:block id="{$id}" xsl:use-attribute-sets="procedure.properties list.block.spacing">
955     <xsl:if test="(title or blockinfo/title or info/title) and $placement = 'before'">
956       <!-- n.b. gentext code tests for $formal.procedures and may make an "informal" -->
957       <!-- heading even though we called formal.object.heading. odd but true. -->
958       <xsl:call-template name="formal.object.heading"/>
959     </xsl:if>
960
961     <xsl:apply-templates select="$preamble"/>
962
963     <fo:list-block xsl:use-attribute-sets="list.block.spacing"
964                    provisional-distance-between-starts="2em"
965                    provisional-label-separation="0.2em">
966       <xsl:apply-templates select="$steps"/>
967     </fo:list-block>
968
969     <xsl:if test="(title or blockinfo/title or info/title) and $placement != 'before'">
970       <!-- n.b. gentext code tests for $formal.procedures and may make an "informal" -->
971       <!-- heading even though we called formal.object.heading. odd but true. -->
972       <xsl:call-template name="formal.object.heading"/>
973     </xsl:if>
974   </fo:block>
975 </xsl:template>
976
977 <xsl:template match="procedure/title">
978 </xsl:template>
979
980 <xsl:template match="substeps">
981   <fo:list-block xsl:use-attribute-sets="list.block.spacing"
982                  provisional-distance-between-starts="2em"
983                  provisional-label-separation="0.2em">
984     <xsl:apply-templates/>
985   </fo:list-block>
986 </xsl:template>
987
988 <xsl:template match="procedure/step|substeps/step">
989   <xsl:variable name="id">
990     <xsl:call-template name="object.id"/>
991   </xsl:variable>
992
993   <xsl:variable name="keep.together">
994     <xsl:call-template name="pi.dbfo_keep-together"/>
995   </xsl:variable>
996
997   <fo:list-item xsl:use-attribute-sets="list.item.spacing">
998     <xsl:if test="$keep.together != ''">
999       <xsl:attribute name="keep-together.within-column"><xsl:value-of
1000                       select="$keep.together"/></xsl:attribute>
1001     </xsl:if>
1002     <fo:list-item-label end-indent="label-end()">
1003       <fo:block id="{$id}">
1004         <!-- dwc: fix for one step procedures. Use a bullet if there's no step 2 -->
1005         <xsl:choose>
1006           <xsl:when test="count(../step) = 1">
1007             <xsl:text>&#x2022;</xsl:text>
1008           </xsl:when>
1009           <xsl:otherwise>
1010             <xsl:apply-templates select="." mode="number">
1011               <xsl:with-param name="recursive" select="0"/>
1012             </xsl:apply-templates>.
1013           </xsl:otherwise>
1014         </xsl:choose>
1015       </fo:block>
1016     </fo:list-item-label>
1017     <fo:list-item-body start-indent="body-start()">
1018       <fo:block>
1019         <xsl:apply-templates/>
1020       </fo:block>
1021     </fo:list-item-body>
1022   </fo:list-item>
1023 </xsl:template>
1024
1025 <xsl:template match="stepalternatives">
1026   <fo:list-block provisional-distance-between-starts="2em"
1027                  provisional-label-separation="0.2em">
1028     <xsl:apply-templates select="step"/>
1029   </fo:list-block>
1030 </xsl:template>
1031
1032 <xsl:template match="stepalternatives/step">
1033   <xsl:variable name="id">
1034     <xsl:call-template name="object.id"/>
1035   </xsl:variable>
1036
1037   <xsl:variable name="keep.together">
1038     <xsl:call-template name="pi.dbfo_keep-together"/>
1039   </xsl:variable>
1040
1041   <fo:list-item xsl:use-attribute-sets="list.item.spacing">
1042     <xsl:if test="$keep.together != ''">
1043       <xsl:attribute name="keep-together.within-column"><xsl:value-of
1044                       select="$keep.together"/></xsl:attribute>
1045     </xsl:if>
1046     <fo:list-item-label end-indent="label-end()">
1047       <fo:block id="{$id}">
1048         <xsl:text>&#x2022;</xsl:text>
1049       </fo:block>
1050     </fo:list-item-label>
1051     <fo:list-item-body start-indent="body-start()">
1052       <fo:block>
1053         <xsl:apply-templates/>
1054       </fo:block>
1055     </fo:list-item-body>
1056   </fo:list-item>
1057 </xsl:template>
1058
1059 <xsl:template match="step/title">
1060   <fo:block font-weight="bold"
1061             keep-together.within-column="always" 
1062             keep-with-next.within-column="always">
1063     <xsl:apply-templates/>
1064   </fo:block>
1065 </xsl:template>
1066
1067 <!-- Add (Optional) when the step is optional -->
1068 <xsl:template match="step[@performance = 'optional']/*[1][self::para]" priority="3">
1069   <xsl:variable name="keep.together">
1070     <xsl:call-template name="pi.dbfo_keep-together"/>
1071   </xsl:variable>
1072   <fo:block xsl:use-attribute-sets="para.properties">
1073     <xsl:if test="$keep.together != ''">
1074       <xsl:attribute name="keep-together.within-column"><xsl:value-of
1075                       select="$keep.together"/></xsl:attribute>
1076     </xsl:if>
1077     <xsl:call-template name="anchor"/>
1078     <xsl:if test="$mark.optional.procedure.steps != 0">
1079       <xsl:call-template name="optional.step.marker"/>
1080     </xsl:if>
1081     <xsl:apply-templates/>
1082   </fo:block>
1083 </xsl:template>
1084
1085 <xsl:template name="optional.step.marker">
1086   <fo:inline>
1087     <xsl:call-template name="gentext">
1088       <xsl:with-param name="key">optional-step</xsl:with-param>
1089     </xsl:call-template>
1090   </fo:inline>
1091 </xsl:template>
1092 <!-- ==================================================================== -->
1093
1094 <xsl:template match="segmentedlist">
1095   <xsl:variable name="presentation">
1096     <xsl:call-template name="pi.dbfo_list-presentation"/>
1097   </xsl:variable>
1098
1099   <xsl:variable name="keep.together">
1100     <xsl:call-template name="pi.dbfo_keep-together"/>
1101   </xsl:variable>
1102
1103   <xsl:variable name="id">
1104     <xsl:call-template name="object.id"/>
1105   </xsl:variable>
1106
1107   <xsl:choose>
1108     <xsl:when test="$presentation = 'table'">
1109       <fo:block id="{$id}">
1110         <xsl:if test="$keep.together != ''">
1111           <xsl:attribute name="keep-together.within-column"><xsl:value-of
1112                           select="$keep.together"/></xsl:attribute>
1113         </xsl:if>
1114         <xsl:apply-templates select="." mode="seglist-table"/>
1115       </fo:block>
1116     </xsl:when>
1117     <xsl:when test="$presentation = 'list'">
1118       <fo:block id="{$id}">
1119         <xsl:if test="$keep.together != ''">
1120           <xsl:attribute name="keep-together.within-column"><xsl:value-of
1121                           select="$keep.together"/></xsl:attribute>
1122         </xsl:if>
1123         <xsl:apply-templates/>
1124       </fo:block>
1125     </xsl:when>
1126     <xsl:when test="$segmentedlist.as.table != 0">
1127       <fo:block id="{$id}">
1128         <xsl:if test="$keep.together != ''">
1129           <xsl:attribute name="keep-together.within-column"><xsl:value-of
1130                           select="$keep.together"/></xsl:attribute>
1131         </xsl:if>
1132         <xsl:apply-templates select="." mode="seglist-table"/>
1133       </fo:block>
1134     </xsl:when>
1135     <xsl:otherwise>
1136       <fo:block id="{$id}">
1137         <xsl:if test="$keep.together != ''">
1138           <xsl:attribute name="keep-together.within-column"><xsl:value-of
1139                           select="$keep.together"/></xsl:attribute>
1140         </xsl:if>
1141
1142         <xsl:apply-templates/>
1143       </fo:block>
1144     </xsl:otherwise>
1145   </xsl:choose>
1146 </xsl:template>
1147
1148 <xsl:template match="segmentedlist/title">
1149   <xsl:apply-templates select="." mode="list.title.mode" />
1150 </xsl:template>
1151
1152 <xsl:template match="segtitle">
1153 </xsl:template>
1154
1155 <xsl:template match="segtitle" mode="segtitle-in-seg">
1156   <xsl:apply-templates/>
1157 </xsl:template>
1158
1159 <xsl:template match="seglistitem">
1160   <xsl:variable name="id">
1161     <xsl:call-template name="object.id"/>
1162   </xsl:variable>
1163   <fo:block id="{$id}">
1164     <xsl:apply-templates/>
1165   </fo:block>
1166 </xsl:template>
1167
1168 <xsl:template match="seg">
1169   <xsl:variable name="segnum" select="count(preceding-sibling::seg)+1"/>
1170   <xsl:variable name="seglist" select="ancestor::segmentedlist"/>
1171   <xsl:variable name="segtitles" select="$seglist/segtitle"/>
1172
1173   <!--
1174      Note: segtitle is only going to be the right thing in a well formed
1175      SegmentedList.  If there are too many Segs or too few SegTitles,
1176      you'll get something odd...maybe an error
1177   -->
1178
1179   <fo:block>
1180     <fo:inline font-weight="bold">
1181       <xsl:apply-templates select="$segtitles[$segnum=position()]"
1182                            mode="segtitle-in-seg"/>
1183       <xsl:text>: </xsl:text>
1184     </fo:inline>
1185     <xsl:apply-templates/>
1186   </fo:block>
1187 </xsl:template>
1188
1189 <xsl:template match="segmentedlist" mode="seglist-table">
1190   <xsl:apply-templates select="title" mode="list.title.mode" />
1191   <fo:table table-layout="fixed">
1192     <xsl:call-template name="segmentedlist.table.columns">
1193       <xsl:with-param name="cols" select="count(segtitle)"/>
1194     </xsl:call-template>
1195     <fo:table-header start-indent="0pt" end-indent="0pt">
1196       <fo:table-row>
1197         <xsl:apply-templates select="segtitle" mode="seglist-table"/>
1198       </fo:table-row>
1199     </fo:table-header>
1200     <fo:table-body start-indent="0pt" end-indent="0pt">
1201       <xsl:apply-templates select="seglistitem" mode="seglist-table"/>
1202     </fo:table-body>
1203   </fo:table>
1204 </xsl:template>
1205
1206 <xsl:template name="segmentedlist.table.columns">
1207   <xsl:param name="cols" select="1"/>
1208   <xsl:param name="curcol" select="1"/>
1209
1210   <fo:table-column column-number="{$curcol}"
1211                    column-width="proportional-column-width(1)"/>
1212   <xsl:if test="$curcol &lt; $cols">
1213     <xsl:call-template name="segmentedlist.table.columns">
1214       <xsl:with-param name="cols" select="$cols"/>
1215       <xsl:with-param name="curcol" select="$curcol+1"/>
1216     </xsl:call-template>
1217   </xsl:if>
1218 </xsl:template>
1219
1220 <xsl:template match="segtitle" mode="seglist-table">
1221   <fo:table-cell>
1222     <fo:block font-weight="bold">
1223       <xsl:apply-templates/>
1224     </fo:block>
1225   </fo:table-cell>
1226 </xsl:template>
1227
1228 <xsl:template match="seglistitem" mode="seglist-table">
1229   <xsl:variable name="id">
1230     <xsl:call-template name="object.id"/>
1231   </xsl:variable>
1232   <fo:table-row id="{$id}">
1233     <xsl:apply-templates mode="seglist-table"/>
1234   </fo:table-row>
1235 </xsl:template>
1236
1237 <xsl:template match="seg" mode="seglist-table">
1238   <fo:table-cell>
1239     <fo:block>
1240       <xsl:apply-templates/>
1241     </fo:block>
1242   </fo:table-cell>
1243 </xsl:template>
1244
1245 <!-- ==================================================================== -->
1246
1247 <xsl:template match="calloutlist">
1248   <xsl:variable name="id">
1249   <xsl:call-template name="object.id"/>
1250   </xsl:variable>
1251
1252   <xsl:variable name="pi-label-width">
1253     <xsl:call-template name="pi.dbfo_label-width"/>
1254   </xsl:variable>
1255
1256   <fo:block id="{$id}"
1257             text-align="{$alignment}">
1258     <!-- The above restores alignment altered by image align attribute -->
1259     <xsl:if test="title|info/title">
1260       <xsl:apply-templates select="(title|info/title)[1]" 
1261                            mode="list.title.mode"/>
1262     </xsl:if>
1263
1264     <!-- Preserve order of PIs and comments -->
1265     <xsl:apply-templates 
1266          select="*[not(self::callout or self::title or self::titleabbrev)]
1267                    |comment()[not(preceding-sibling::callout)]
1268                    |processing-instruction()[not(preceding-sibling::callout)]"/>
1269
1270     <fo:list-block xsl:use-attribute-sets="calloutlist.properties">
1271
1272       <xsl:if test="$pi-label-width != ''">
1273         <xsl:attribute name="provisional-distance-between-starts">
1274           <xsl:value-of select="$pi-label-width"/>
1275         </xsl:attribute>
1276       </xsl:if>
1277       
1278       <xsl:apply-templates select="callout
1279                                 |comment()[preceding-sibling::callout]
1280                                 |processing-instruction()[preceding-sibling::callout]"/>
1281     </fo:list-block>
1282   </fo:block>
1283 </xsl:template>
1284
1285 <xsl:template match="calloutlist/title">
1286 </xsl:template>
1287
1288 <xsl:template match="callout">
1289   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
1290
1291   <xsl:variable name="keep.together">
1292     <xsl:call-template name="pi.dbfo_keep-together"/>
1293   </xsl:variable>
1294
1295   <fo:list-item id="{$id}" xsl:use-attribute-sets="callout.properties">
1296     <xsl:if test="$keep.together != ''">
1297       <xsl:attribute name="keep-together.within-column"><xsl:value-of
1298                       select="$keep.together"/></xsl:attribute>
1299     </xsl:if>
1300     <fo:list-item-label end-indent="label-end()">
1301       <fo:block>
1302         <xsl:call-template name="callout.arearefs">
1303           <xsl:with-param name="arearefs" select="@arearefs"/>
1304         </xsl:call-template>
1305       </fo:block>
1306     </fo:list-item-label>
1307     <fo:list-item-body start-indent="body-start()">
1308       <fo:block>
1309         <xsl:apply-templates/>
1310       </fo:block>
1311     </fo:list-item-body>
1312   </fo:list-item>
1313 </xsl:template>
1314
1315 <xsl:template name="callout.arearefs">
1316   <xsl:param name="arearefs"></xsl:param>
1317   <xsl:if test="$arearefs!=''">
1318     <xsl:choose>
1319       <xsl:when test="substring-before($arearefs,' ')=''">
1320         <xsl:call-template name="callout.arearef">
1321           <xsl:with-param name="arearef" select="$arearefs"/>
1322         </xsl:call-template>
1323       </xsl:when>
1324       <xsl:otherwise>
1325         <xsl:call-template name="callout.arearef">
1326           <xsl:with-param name="arearef"
1327                           select="substring-before($arearefs,' ')"/>
1328         </xsl:call-template>
1329       </xsl:otherwise>
1330     </xsl:choose>
1331     <xsl:call-template name="callout.arearefs">
1332       <xsl:with-param name="arearefs"
1333                       select="substring-after($arearefs,' ')"/>
1334     </xsl:call-template>
1335   </xsl:if>
1336 </xsl:template>
1337
1338 <xsl:template name="callout.arearef">
1339   <xsl:param name="arearef"></xsl:param>
1340   <xsl:variable name="targets" select="key('id',$arearef)"/>
1341   <xsl:variable name="target" select="$targets[1]"/>
1342
1343   <xsl:choose>
1344     <xsl:when test="count($target)=0">
1345       <xsl:value-of select="$arearef"/>
1346       <xsl:text>: ???</xsl:text>
1347     </xsl:when>
1348     <xsl:when test="local-name($target)='co'">
1349       <fo:basic-link internal-destination="{$arearef}">
1350         <xsl:apply-templates select="$target" mode="callout-bug"/>
1351       </fo:basic-link>
1352     </xsl:when>
1353     <xsl:when test="local-name($target)='areaset'">
1354       <xsl:call-template name="callout-bug">
1355         <xsl:with-param name="conum">
1356           <xsl:apply-templates select="$target" mode="conumber"/>
1357         </xsl:with-param>
1358       </xsl:call-template>
1359     </xsl:when>
1360     <xsl:when test="local-name($target)='area'">
1361       <xsl:choose>
1362         <xsl:when test="$target/parent::areaset">
1363           <xsl:call-template name="callout-bug">
1364             <xsl:with-param name="conum">
1365               <xsl:apply-templates select="$target/parent::areaset"
1366                                    mode="conumber"/>
1367             </xsl:with-param>
1368           </xsl:call-template>
1369         </xsl:when>
1370         <xsl:otherwise>
1371           <xsl:call-template name="callout-bug">
1372             <xsl:with-param name="conum">
1373               <xsl:apply-templates select="$target" mode="conumber"/>
1374             </xsl:with-param>
1375           </xsl:call-template>
1376         </xsl:otherwise>
1377       </xsl:choose>
1378     </xsl:when>
1379     <xsl:otherwise>
1380       <xsl:text>???</xsl:text>
1381     </xsl:otherwise>
1382   </xsl:choose>
1383 </xsl:template>
1384
1385 <!-- ==================================================================== -->
1386
1387 <xsl:template name="orderedlist-starting-number">
1388   <xsl:param name="list" select="."/>
1389   <xsl:variable name="pi-start">
1390     <xsl:call-template name="pi.dbfo_start">
1391       <xsl:with-param name="node" select="$list"/>
1392     </xsl:call-template>
1393   </xsl:variable>
1394   <xsl:call-template name="output-orderedlist-starting-number">
1395     <xsl:with-param name="list" select="$list"/>
1396     <xsl:with-param name="pi-start" select="$pi-start"/>
1397   </xsl:call-template>
1398 </xsl:template>
1399
1400 </xsl:stylesheet>