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$
8     ********************************************************************
9
10     This file is part of the XSL DocBook Stylesheet distribution.
11     See /README or http://nwalsh.com/docbook/xsl/ for copyright
12     and other information.
13
14     ******************************************************************** -->
15
16<!-- ==================================================================== -->
17
18<xsl:template match="itemizedlist">
19  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
20
21  <xsl:if test="title">
22    <xsl:apply-templates select="title" mode="list.title.mode"/>
23  </xsl:if>
24
25  <fo:list-block id="{$id}" xsl:use-attribute-sets="list.block.spacing"
26                 provisional-distance-between-starts="1.5em"
27                 provisional-label-separation="0.2em">
28    <xsl:apply-templates/>
29  </fo:list-block>
30</xsl:template>
31
32<xsl:template match="itemizedlist/title|orderedlist/title|variablelist/title">
33  <!--nop-->
34</xsl:template>
35
36<xsl:template match="itemizedlist/listitem">
37  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
38  <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
39    <fo:list-item-label end-indent="label-end()">
40      <fo:block>
41        <xsl:text>&#x2022;</xsl:text>
42      </fo:block>
43    </fo:list-item-label>
44    <fo:list-item-body start-indent="body-start()">
45      <xsl:apply-templates/>
46    </fo:list-item-body>
47  </fo:list-item>
48</xsl:template>
49
50<xsl:template match="orderedlist">
51  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
52
53  <xsl:if test="title">
54    <xsl:apply-templates select="title" mode="list.title.mode"/>
55  </xsl:if>
56
57  <fo:list-block id="{$id}" xsl:use-attribute-sets="list.block.spacing"
58                 provisional-distance-between-starts="2em"
59                 provisional-label-separation="0.2em">
60    <xsl:apply-templates/>
61  </fo:list-block>
62</xsl:template>
63
64<xsl:template match="orderedlist/listitem">
65  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
66  <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
67    <fo:list-item-label end-indent="label-end()">
68      <fo:block>
69        <xsl:number count="listitem" format="1."/>
70      </fo:block>
71    </fo:list-item-label>
72    <fo:list-item-body start-indent="body-start()">
73      <xsl:apply-templates/>
74    </fo:list-item-body>
75  </fo:list-item>
76</xsl:template>
77
78<xsl:template match="listitem/para[1]
79                     |listitem/simpara[1]
80                     |listitem/formalpara[1]
81                     |callout/para[1]
82                     |callout/simpara[1]
83                     |callout/formalpara[1]"
84              priority="2">
85  <fo:block>
86    <xsl:apply-templates/>
87  </fo:block>
88</xsl:template>
89
90<xsl:template match="variablelist">
91  <xsl:variable name="id">
92    <xsl:call-template name="object.id"/>
93  </xsl:variable>
94
95  <xsl:variable name="termlength">
96    <xsl:choose>
97      <!-- FIXME: handle @termlength="1in" -->
98      <xsl:when test="@termlength">
99        <xsl:value-of select="@termlength"/>
100        <xsl:text>em</xsl:text>
101      </xsl:when>
102      <!-- FIXME: calculate some reasonable width -->
103      <xsl:otherwise>
104        <xsl:text>1in</xsl:text>
105      </xsl:otherwise>
106    </xsl:choose>
107  </xsl:variable>
108
109  <xsl:if test="title">
110    <xsl:apply-templates select="title" mode="list.title.mode"/>
111  </xsl:if>
112
113  <fo:list-block id="{$id}"
114                 provisional-distance-between-starts="{$termlength}"
115                 provisional-label-separation="0.25in"
116                 xsl:use-attribute-sets="list.block.spacing">
117    <xsl:apply-templates/>
118  </fo:list-block>
119</xsl:template>
120
121<xsl:template match="varlistentry">
122  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
123  <fo:list-item id="{$id}" xsl:use-attribute-sets="list.item.spacing">
124    <fo:list-item-label end-indent="label-end()">
125      <fo:block>
126        <xsl:apply-templates select="term"/>
127      </fo:block>
128    </fo:list-item-label>
129    <fo:list-item-body start-indent="body-start()">
130      <xsl:apply-templates select="listitem"/>
131    </fo:list-item-body>
132  </fo:list-item>
133</xsl:template>
134
135<xsl:template match="varlistentry/term">
136  <fo:inline><xsl:apply-templates/>, </fo:inline>
137</xsl:template>
138
139<xsl:template match="varlistentry/term[position()=last()]" priority="2">
140  <fo:inline><xsl:apply-templates/></fo:inline>
141</xsl:template>
142
143<xsl:template match="varlistentry/listitem">
144  <xsl:apply-templates/>
145</xsl:template>
146
147<!-- ==================================================================== -->
148
149<xsl:template match="title" mode="list.title.mode">
150  <fo:block font-size="12pt" font-weight="bold">
151    <xsl:apply-templates/>
152  </fo:block>
153</xsl:template>
154
155<!-- ==================================================================== -->
156
157<xsl:template match="simplelist">
158  <!-- with no type specified, the default is 'vert' -->
159  <fo:table>
160    <fo:table-body>
161      <xsl:call-template name="simplelist.vert">
162	<xsl:with-param name="cols">
163	  <xsl:choose>
164	    <xsl:when test="@columns">
165	      <xsl:value-of select="@columns"/>
166	    </xsl:when>
167	    <xsl:otherwise>1</xsl:otherwise>
168	  </xsl:choose>
169	</xsl:with-param>
170      </xsl:call-template>
171    </fo:table-body>
172  </fo:table>
173</xsl:template>
174
175<xsl:template match="simplelist[@type='inline']">
176  <fo:inline><xsl:apply-templates/></fo:inline>
177</xsl:template>
178
179<xsl:template match="simplelist[@type='horiz']">
180  <fo:table>
181    <fo:table-body>
182      <xsl:call-template name="simplelist.horiz">
183	<xsl:with-param name="cols">
184	  <xsl:choose>
185	    <xsl:when test="@columns">
186	      <xsl:value-of select="@columns"/>
187	    </xsl:when>
188	    <xsl:otherwise>1</xsl:otherwise>
189	  </xsl:choose>
190	</xsl:with-param>
191      </xsl:call-template>
192    </fo:table-body>
193  </fo:table>
194</xsl:template>
195
196<xsl:template match="simplelist[@type='vert']">
197  <fo:table>
198    <fo:table-body>
199      <xsl:call-template name="simplelist.vert">
200	<xsl:with-param name="cols">
201	  <xsl:choose>
202	    <xsl:when test="@columns">
203	      <xsl:value-of select="@columns"/>
204	    </xsl:when>
205	    <xsl:otherwise>1</xsl:otherwise>
206	  </xsl:choose>
207	</xsl:with-param>
208      </xsl:call-template>
209    </fo:table-body>
210  </fo:table>
211</xsl:template>
212
213<xsl:template name="simplelist.horiz">
214  <xsl:param name="cols">1</xsl:param>
215  <xsl:param name="cell">1</xsl:param>
216  <xsl:param name="members" select="/member"/>
217
218  <xsl:if test="$cell &lt;= count($members)">
219    <fo:table-row>
220      <xsl:call-template name="simplelist.horiz.row">
221        <xsl:with-param name="cols" select="$cols"/>
222        <xsl:with-param name="cell" select="$cell"/>
223        <xsl:with-param name="members" select="$members"/>
224      </xsl:call-template>
225   </fo:table-row>
226    <xsl:call-template name="simplelist.horiz">
227      <xsl:with-param name="cols" select="$cols"/>
228      <xsl:with-param name="cell" select="$cell + $cols"/>
229      <xsl:with-param name="members" select="$members"/>
230    </xsl:call-template>
231  </xsl:if>
232</xsl:template>
233
234<xsl:template name="simplelist.horiz.row">
235  <xsl:param name="cols">1</xsl:param>
236  <xsl:param name="cell">1</xsl:param>
237  <xsl:param name="members" select="/member"/>
238  <xsl:param name="curcol">1</xsl:param>
239
240  <xsl:if test="$curcol &lt;= $cols">
241    <fo:table-cell>
242      <fo:block>
243        <xsl:if test="$members[position()=$cell]">
244          <xsl:apply-templates select="$members[position()=$cell]"/>
245        </xsl:if>
246      </fo:block>
247    </fo:table-cell>
248    <xsl:call-template name="simplelist.horiz.row">
249      <xsl:with-param name="cols" select="$cols"/>
250      <xsl:with-param name="cell" select="$cell+1"/>
251      <xsl:with-param name="members" select="$members"/>
252      <xsl:with-param name="curcol" select="$curcol+1"/>
253    </xsl:call-template>
254  </xsl:if>
255</xsl:template>
256
257<xsl:template name="simplelist.vert">
258  <xsl:param name="cols">1</xsl:param>
259  <xsl:param name="cell">1</xsl:param>
260  <xsl:param name="members" select="/member"/>
261  <xsl:param name="rows"
262             select="floor((count($members)+$cols - 1) div $cols)"/>
263
264  <xsl:if test="$cell &lt;= $rows">
265    <fo:table-row>
266      <xsl:call-template name="simplelist.vert.row">
267        <xsl:with-param name="cols" select="$cols"/>
268        <xsl:with-param name="rows" select="$rows"/>
269        <xsl:with-param name="cell" select="$cell"/>
270        <xsl:with-param name="members" select="$members"/>
271      </xsl:call-template>
272   </fo:table-row>
273    <xsl:call-template name="simplelist.vert">
274      <xsl:with-param name="cols" select="$cols"/>
275      <xsl:with-param name="cell" select="$cell+1"/>
276      <xsl:with-param name="members" select="$members"/>
277      <xsl:with-param name="rows" select="$rows"/>
278    </xsl:call-template>
279  </xsl:if>
280</xsl:template>
281
282<xsl:template name="simplelist.vert.row">
283  <xsl:param name="cols">1</xsl:param>
284  <xsl:param name="rows">1</xsl:param>
285  <xsl:param name="cell">1</xsl:param>
286  <xsl:param name="members" select="/member"/>
287  <xsl:param name="curcol">1</xsl:param>
288
289  <xsl:if test="$curcol &lt;= $cols">
290    <fo:table-cell>
291      <fo:block>
292        <xsl:if test="$members[position()=$cell]">
293          <xsl:apply-templates select="$members[position()=$cell]"/>
294        </xsl:if>
295      </fo:block>
296    </fo:table-cell>
297    <xsl:call-template name="simplelist.vert.row">
298      <xsl:with-param name="cols" select="$cols"/>
299      <xsl:with-param name="rows" select="$rows"/>
300      <xsl:with-param name="cell" select="$cell+$rows"/>
301      <xsl:with-param name="members" select="$members"/>
302      <xsl:with-param name="curcol" select="$curcol+1"/>
303    </xsl:call-template>
304  </xsl:if>
305</xsl:template>
306
307<xsl:template match="member">
308  <xsl:apply-templates/>
309</xsl:template>
310
311<xsl:template match="simplelist[@type='inline']/member">
312  <xsl:apply-templates/>
313  <xsl:text>, </xsl:text>
314</xsl:template>
315
316<xsl:template match="simplelist[@type='inline']/member[position()=last()]"
317              priority="2">
318  <xsl:apply-templates/>
319</xsl:template>
320
321<!-- ==================================================================== -->
322
323<xsl:template match="procedure">
324  <xsl:variable name="title" select="title"/>
325  <xsl:variable name="preamble"
326                select="*[not(self::step or self::title)]"/>
327  <xsl:variable name="steps" select="step"/>
328
329  <fo:block space-before.optimum="1em"
330            space-before.minimum="0.8em"
331            space-before.maximum="1.2em">
332    <xsl:if test="/title">
333      <fo:block font-weight="bold">
334        <xsl:apply-templates select="/title" mode="procedure.title.mode"/>
335      </fo:block>
336    </xsl:if>
337
338    <xsl:apply-templates select="$preamble"/>
339
340    <fo:list-block xsl:use-attribute-sets="list.block.spacing"
341                   provisional-distance-between-starts="2em"
342                   provisional-label-separation="0.2em">
343      <xsl:apply-templates select="$steps"/>
344    </fo:list-block>
345  </fo:block>
346</xsl:template>
347
348<xsl:template match="procedure/title">
349</xsl:template>
350
351<xsl:template match="procedure/title" mode="procedure.title.mode">
352  <xsl:apply-templates/>
353</xsl:template>
354
355<xsl:template match="substeps">
356  <fo:list-block xsl:use-attribute-sets="list.block.spacing"
357                 provisional-distance-between-starts="2em"
358                 provisional-label-separation="0.2em">
359    <xsl:apply-templates/>
360  </fo:list-block>
361</xsl:template>
362
363<xsl:template match="step">
364  <xsl:variable name="depth" select="count(ancestor::substeps)"/>
365  <xsl:variable name="type" select="$depth mod 5"/>
366
367  <fo:list-item>
368    <fo:list-item-label end-indent="label-end()">
369      <fo:block>
370        <xsl:choose>
371          <xsl:when test="$depth = 0">
372            <xsl:number count="step" format="1."/>
373          </xsl:when>
374          <xsl:when test="$type = 1">
375            <xsl:number count="step" format="a."/>
376          </xsl:when>
377          <xsl:when test="$type = 2">
378            <xsl:number count="step" format="i."/>
379          </xsl:when>
380          <xsl:when test="$type = 3">
381            <xsl:number count="step" format="A."/>
382          </xsl:when>
383          <xsl:when test="$type = 4">
384            <xsl:number count="step" format="I."/>
385          </xsl:when>
386          <xsl:when test="$type = 0">
387            <xsl:number count="step" format="1."/>
388          </xsl:when>
389        </xsl:choose>
390      </fo:block>
391    </fo:list-item-label>
392    <fo:list-item-body start-indent="body-start()">
393      <xsl:apply-templates/>
394    </fo:list-item-body>
395  </fo:list-item>
396</xsl:template>
397
398<!-- ==================================================================== -->
399
400<xsl:template match="segmentedlist">
401  <xsl:apply-templates/>
402</xsl:template>
403
404<xsl:template match="segmentedlist/title">
405  <fo:block font-weight="bold">
406    <xsl:apply-templates/>
407  </fo:block>
408</xsl:template>
409
410<xsl:template match="segtitle">
411</xsl:template>
412
413<xsl:template match="segtitle" mode="segtitle-in-seg">
414  <xsl:apply-templates/>
415</xsl:template>
416
417<xsl:template match="seglistitem">
418  <xsl:apply-templates/>
419</xsl:template>
420
421<xsl:template match="seg">
422  <xsl:variable name="segnum" select="position()"/>
423  <xsl:variable name="seglist" select="ancestor::segmentedlist"/>
424  <xsl:variable name="segtitles" select="$seglist/segtitle"/>
425
426  <!--
427     Note: segtitle is only going to be the right thing in a well formed
428     SegmentedList.  If there are too many Segs or too few SegTitles,
429     you'll get something odd...maybe an error
430  -->
431
432  <fo:block>
433    <fo:inline font-weight="bold">
434      <xsl:apply-templates select="$segtitles[$segnum=position()]"
435                           mode="segtitle-in-seg"/>
436      <xsl:text>: </xsl:text>
437    </fo:inline>
438    <xsl:apply-templates/>
439  </fo:block>
440</xsl:template>
441
442<!-- ==================================================================== -->
443
444<xsl:template match="calloutlist">
445  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
446
447  <fo:block id="{$id}">
448    <xsl:if test="/title">
449      <fo:block font-weight="bold">
450        <xsl:apply-templates select="/title" mode="calloutlist.title.mode"/>
451      </fo:block>
452    </xsl:if>
453
454    <fo:list-block space-before.optimum="1em"
455                   space-before.minimum="0.8em"
456                   space-before.maximum="1.2em"
457                   provisional-distance-between-starts="2.2em"
458                   provisional-label-separation="0.2em">
459      <xsl:apply-templates/>
460    </fo:list-block>
461  </fo:block>
462</xsl:template>
463
464<xsl:template match="calloutlist/title">
465</xsl:template>
466
467<xsl:template match="calloutlist/title" mode="calloutlist.title.mode">
468  <xsl:apply-templates/>
469</xsl:template>
470
471<xsl:template match="callout">
472  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
473  <fo:list-item id="{$id}">
474    <fo:list-item-label end-indent="label-end()">
475      <fo:block>
476        <xsl:call-template name="callout.arearefs">
477          <xsl:with-param name="arearefs" select="@arearefs"/>
478        </xsl:call-template>
479      </fo:block>
480    </fo:list-item-label>
481    <fo:list-item-body start-indent="body-start()">
482      <xsl:apply-templates/>
483    </fo:list-item-body>
484  </fo:list-item>
485</xsl:template>
486
487<xsl:template name="callout.arearefs">
488  <xsl:param name="arearefs"></xsl:param>
489  <xsl:if test="$arearefs!=''">
490    <xsl:choose>
491      <xsl:when test="substring-before($arearefs,' ')=''">
492        <xsl:call-template name="callout.arearef">
493          <xsl:with-param name="arearef" select="$arearefs"/>
494        </xsl:call-template>
495      </xsl:when>
496      <xsl:otherwise>
497        <xsl:call-template name="callout.arearef">
498          <xsl:with-param name="arearef"
499                          select="substring-before($arearefs,' ')"/>
500        </xsl:call-template>
501      </xsl:otherwise>
502    </xsl:choose>
503    <xsl:call-template name="callout.arearefs">
504      <xsl:with-param name="arearefs"
505                      select="substring-after($arearefs,' ')"/>
506    </xsl:call-template>
507  </xsl:if>
508</xsl:template>
509
510<xsl:template name="callout.arearef">
511  <xsl:param name="arearef"></xsl:param>
512  <xsl:variable name="targets" select="id($arearef)"/>
513  <xsl:variable name="target" select="$targets[1]"/>
514
515  <xsl:choose>
516    <xsl:when test="count($target)=0">
517      <xsl:value-of select="$arearef"/>
518      <xsl:text>: ???</xsl:text>
519    </xsl:when>
520    <xsl:when test="local-name($target)='co'">
521      <xsl:apply-templates select="$target" mode="callout-bug"/>
522    </xsl:when>
523    <xsl:when test="local-name($target)='areaset'">
524      <xsl:call-template name="callout-bug">
525        <xsl:with-param name="conum">
526          <xsl:apply-templates select="$target" mode="conumber"/>
527        </xsl:with-param>
528      </xsl:call-template>
529    </xsl:when>
530    <xsl:when test="local-name($target)='area'">
531      <xsl:choose>
532        <xsl:when test="$target/parent::areaset">
533          <xsl:call-template name="callout-bug">
534            <xsl:with-param name="conum">
535              <xsl:apply-templates select="$target/parent::areaset"
536                                   mode="conumber"/>
537            </xsl:with-param>
538          </xsl:call-template>
539        </xsl:when>
540        <xsl:otherwise>
541          <xsl:call-template name="callout-bug">
542            <xsl:with-param name="conum">
543              <xsl:apply-templates select="$target" mode="conumber"/>
544            </xsl:with-param>
545          </xsl:call-template>
546        </xsl:otherwise>
547      </xsl:choose>
548    </xsl:when>
549    <xsl:otherwise>
550      <xsl:text>???</xsl:text>
551    </xsl:otherwise>
552  </xsl:choose>
553</xsl:template>
554
555<!-- ==================================================================== -->
556
557</xsl:stylesheet>
558
559