]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/evergreen_docbook_files/docbook-xsl-1.75.2/fo/autotoc.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 / autotoc.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                 xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
5                 version='1.0'>
6
7 <!-- ********************************************************************
8      $Id: autotoc.xsl 8286 2009-03-06 22:53:04Z bobstayton $
9      ********************************************************************
10
11      This file is part of the XSL DocBook Stylesheet distribution.
12      See ../README or http://docbook.sf.net/release/xsl/current/ for
13      copyright and other information.
14
15      ******************************************************************** -->
16
17 <!-- ==================================================================== -->
18
19 <xsl:template name="set.toc">
20
21   <xsl:param name="toc-context" select="."/>
22
23   <xsl:variable name="id">
24     <xsl:call-template name="object.id"/>
25   </xsl:variable>
26
27   <xsl:variable name="cid">
28     <xsl:call-template name="object.id">
29       <xsl:with-param name="object" select="$toc-context"/>
30     </xsl:call-template>
31   </xsl:variable>
32
33   <xsl:variable name="nodes" select="book|set|setindex"/>
34
35   <xsl:if test="$nodes">
36     <fo:block id="toc...{$id}"
37               xsl:use-attribute-sets="toc.margin.properties">
38       <xsl:if test="$axf.extensions != 0">
39         <xsl:attribute name="axf:outline-level">1</xsl:attribute>
40         <xsl:attribute name="axf:outline-expand">false</xsl:attribute>
41         <xsl:attribute name="axf:outline-title">
42           <xsl:call-template name="gentext">
43             <xsl:with-param name="key" select="'TableofContents'"/>
44           </xsl:call-template>
45         </xsl:attribute>
46       </xsl:if>
47       <xsl:call-template name="table.of.contents.titlepage"/>
48       <xsl:apply-templates select="$nodes" mode="toc">
49         <xsl:with-param name="toc-context" select="$toc-context"/>
50       </xsl:apply-templates>
51     </fo:block>
52   </xsl:if>
53 </xsl:template>
54
55 <xsl:template name="division.toc">
56   <xsl:param name="toc-context" select="."/>
57   <xsl:param name="toc.title.p" select="true()"/>
58
59   <xsl:variable name="cid">
60     <xsl:call-template name="object.id">
61       <xsl:with-param name="object" select="$toc-context"/>
62     </xsl:call-template>
63   </xsl:variable>
64
65   <xsl:variable name="nodes"
66                 select="$toc-context/part
67                         |$toc-context/reference
68                         |$toc-context/preface
69                         |$toc-context/chapter
70                         |$toc-context/appendix
71                         |$toc-context/article
72                         |$toc-context/bibliography
73                         |$toc-context/glossary
74                         |$toc-context/index"/>
75
76   <xsl:if test="$nodes">
77     <fo:block id="toc...{$cid}"
78               xsl:use-attribute-sets="toc.margin.properties">
79       <xsl:if test="$axf.extensions != 0">
80         <xsl:attribute name="axf:outline-level">1</xsl:attribute>
81         <xsl:attribute name="axf:outline-expand">false</xsl:attribute>
82         <xsl:attribute name="axf:outline-title">
83           <xsl:call-template name="gentext">
84             <xsl:with-param name="key" select="'TableofContents'"/>
85           </xsl:call-template>
86         </xsl:attribute>
87       </xsl:if>
88       <xsl:if test="$toc.title.p">
89         <xsl:call-template name="table.of.contents.titlepage"/>
90       </xsl:if>
91       <xsl:apply-templates select="$nodes" mode="toc">
92         <xsl:with-param name="toc-context" select="$toc-context"/>
93       </xsl:apply-templates>
94     </fo:block>
95   </xsl:if>
96 </xsl:template>
97
98 <xsl:template name="component.toc">
99   <xsl:param name="toc-context" select="."/>
100   <xsl:param name="toc.title.p" select="true()"/>
101
102   <xsl:variable name="id">
103     <xsl:call-template name="object.id"/>
104   </xsl:variable>
105
106   <xsl:variable name="cid">
107     <xsl:call-template name="object.id">
108       <xsl:with-param name="object" select="$toc-context"/>
109     </xsl:call-template>
110   </xsl:variable>
111
112   <xsl:variable name="nodes" select="section|sect1|refentry
113                                      |article|bibliography|glossary
114                                      |qandaset[$qanda.in.toc != 0]
115                                      |appendix|index"/>
116   <xsl:if test="$nodes">
117     <fo:block id="toc...{$id}"
118               xsl:use-attribute-sets="toc.margin.properties">
119       <xsl:if test="$toc.title.p">
120         <xsl:call-template name="table.of.contents.titlepage"/>
121       </xsl:if>
122       <xsl:apply-templates select="$nodes" mode="toc">
123         <xsl:with-param name="toc-context" select="$toc-context"/>
124       </xsl:apply-templates>
125     </fo:block>
126   </xsl:if>
127 </xsl:template>
128
129 <xsl:template name="component.toc.separator">
130   <!-- Customize to output something between
131        component.toc and first output -->
132 </xsl:template>
133
134 <xsl:template name="section.toc">
135   <xsl:param name="toc-context" select="."/>
136   <xsl:param name="toc.title.p" select="true()"/>
137
138   <xsl:variable name="id">
139     <xsl:call-template name="object.id"/>
140   </xsl:variable>
141
142   <xsl:variable name="cid">
143     <xsl:call-template name="object.id">
144       <xsl:with-param name="object" select="$toc-context"/>
145     </xsl:call-template>
146   </xsl:variable>
147
148   <xsl:variable name="nodes"
149                 select="section|sect1|sect2|sect3|sect4|sect5|refentry
150                         |qandaset[$qanda.in.toc != 0]
151                         |bridgehead[$bridgehead.in.toc != 0]"/>
152
153   <xsl:variable name="level">
154     <xsl:call-template name="section.level"/>
155   </xsl:variable>
156
157   <xsl:if test="$nodes">
158     <fo:block id="toc...{$id}"
159               xsl:use-attribute-sets="toc.margin.properties">
160
161       <xsl:if test="$toc.title.p">
162         <xsl:call-template name="section.heading">
163           <xsl:with-param name="level" select="$level + 1"/>
164           <xsl:with-param name="title">
165             <fo:block space-after="0.5em">
166               <xsl:call-template name="gentext">
167                 <xsl:with-param name="key" select="'TableofContents'"/>
168               </xsl:call-template>
169             </fo:block>
170           </xsl:with-param>
171         </xsl:call-template>
172       </xsl:if>
173
174       <xsl:apply-templates select="$nodes" mode="toc">
175         <xsl:with-param name="toc-context" select="$toc-context"/>
176       </xsl:apply-templates>
177     </fo:block>
178   </xsl:if>
179 </xsl:template>
180
181 <xsl:template name="section.toc.separator">
182   <!-- Customize to output something between
183        section.toc and first output -->
184 </xsl:template>
185 <!-- ==================================================================== -->
186
187 <xsl:template name="toc.line">
188   <xsl:param name="toc-context" select="NOTANODE"/>
189
190   <xsl:variable name="id">
191     <xsl:call-template name="object.id"/>
192   </xsl:variable>
193
194   <xsl:variable name="label">
195     <xsl:apply-templates select="." mode="label.markup"/>
196   </xsl:variable>
197
198   <fo:block xsl:use-attribute-sets="toc.line.properties">
199     <fo:inline keep-with-next.within-line="always">
200       <fo:basic-link internal-destination="{$id}">
201         <xsl:if test="$label != ''">
202           <xsl:copy-of select="$label"/>
203           <xsl:value-of select="$autotoc.label.separator"/>
204         </xsl:if>
205         <xsl:apply-templates select="." mode="titleabbrev.markup"/>
206       </fo:basic-link>
207     </fo:inline>
208     <fo:inline keep-together.within-line="always">
209       <xsl:text> </xsl:text>
210       <fo:leader leader-pattern="dots"
211                  leader-pattern-width="3pt"
212                  leader-alignment="reference-area"
213                  keep-with-next.within-line="always"/>
214       <xsl:text> </xsl:text> 
215       <fo:basic-link internal-destination="{$id}">
216         <fo:page-number-citation ref-id="{$id}"/>
217       </fo:basic-link>
218     </fo:inline>
219   </fo:block>
220 </xsl:template>
221
222 <!-- ==================================================================== -->
223 <xsl:template name="qandaset.toc">
224   <xsl:param name="toc-context" select="."/>
225   <xsl:param name="toc.title.p" select="true()"/>
226
227   <xsl:variable name="id">
228     <xsl:call-template name="object.id"/>
229   </xsl:variable>
230
231   <xsl:variable name="cid">
232     <xsl:call-template name="object.id">
233       <xsl:with-param name="object" select="$toc-context"/>
234     </xsl:call-template>
235   </xsl:variable>
236
237   <xsl:variable name="nodes" select="qandadiv|qandaentry"/>
238
239   <xsl:if test="$nodes">
240     <fo:block id="toc...{$id}"
241               xsl:use-attribute-sets="toc.margin.properties">
242       <xsl:if test="$toc.title.p">
243         <xsl:call-template name="table.of.contents.titlepage"/>
244       </xsl:if>
245       <xsl:apply-templates select="$nodes" mode="toc">
246         <xsl:with-param name="toc-context" select="$toc-context"/>
247       </xsl:apply-templates>
248     </fo:block>
249   </xsl:if>
250 </xsl:template>
251
252 <xsl:template name="qandaset.toc.separator">
253   <!-- Customize to output something between
254        qandaset.toc and first output -->
255 </xsl:template>
256
257 <xsl:template match="qandadiv" mode="toc">
258   <xsl:param name="toc-context" select="."/>
259
260   <xsl:variable name="id">
261     <xsl:call-template name="object.id"/>
262   </xsl:variable>
263
264   <xsl:variable name="cid">
265     <xsl:call-template name="object.id">
266       <xsl:with-param name="object" select="$toc-context"/>
267     </xsl:call-template>
268   </xsl:variable>
269
270   <xsl:call-template name="toc.line">
271     <xsl:with-param name="toc-context" select="$toc-context"/>
272   </xsl:call-template>
273
274   <xsl:variable name="nodes" select="qandadiv|qandaentry"/>
275
276   <xsl:if test="$nodes">
277     <fo:block id="toc.{$cid}.{$id}">
278       <xsl:attribute name="margin-{$direction.align.start}">
279         <xsl:call-template name="set.toc.indent"/>
280       </xsl:attribute>
281
282       <xsl:apply-templates select="$nodes" mode="toc">
283         <xsl:with-param name="toc-context" select="$toc-context"/>
284       </xsl:apply-templates>
285     </fo:block>
286   </xsl:if>
287 </xsl:template>
288
289 <xsl:template match="qandaentry" mode="toc">
290   <xsl:apply-templates select="question" mode="toc"/>
291 </xsl:template>
292
293 <xsl:template match="question" mode="toc">
294   <xsl:variable name="firstchunk">
295     <!-- Use a titleabbrev or title if available -->
296     <xsl:choose>
297       <xsl:when test="../blockinfo/titleabbrev">
298         <xsl:apply-templates select="../blockinfo/titleabbrev[1]/node()"/>
299       </xsl:when>
300       <xsl:when test="../blockinfo/title">
301         <xsl:apply-templates select="../blockinfo/title[1]/node()"/>
302       </xsl:when>
303       <xsl:when test="../info/titleabbrev">
304         <xsl:apply-templates select="../info/titleabbrev[1]/node()"/>
305       </xsl:when>
306       <xsl:when test="../titleabbrev">
307         <xsl:apply-templates select="../titleabbrev[1]/node()"/>
308       </xsl:when>
309       <xsl:when test="../info/title">
310         <xsl:apply-templates select="../info/title[1]/node()"/>
311       </xsl:when>
312       <xsl:when test="../title">
313         <xsl:apply-templates select="../title[1]/node()"/>
314       </xsl:when>
315       <xsl:otherwise>
316         <xsl:apply-templates select="(*[local-name(.)!='label'])[1]/node()"/>
317       </xsl:otherwise>
318     </xsl:choose>
319   </xsl:variable>
320
321   <xsl:variable name="deflabel">
322     <xsl:choose>
323       <xsl:when test="ancestor-or-self::*[@defaultlabel]">
324         <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
325                               /@defaultlabel"/>
326       </xsl:when>
327       <xsl:otherwise>
328         <xsl:value-of select="$qanda.defaultlabel"/>
329       </xsl:otherwise>
330     </xsl:choose>
331   </xsl:variable>
332
333   <xsl:variable name="id">
334     <xsl:call-template name="object.id"/>
335   </xsl:variable>
336
337   <xsl:variable name="label">
338     <xsl:apply-templates select="." mode="label.markup"/>
339   </xsl:variable>
340
341   <fo:block xsl:use-attribute-sets="toc.line.properties"
342             end-indent="{$toc.indent.width}pt"
343             last-line-end-indent="-{$toc.indent.width}pt">
344     <xsl:attribute name="margin-{$direction.align.start}">3em</xsl:attribute>
345     <xsl:attribute name="text-indent">-3em</xsl:attribute>
346     <fo:inline keep-with-next.within-line="always">
347       <fo:basic-link internal-destination="{$id}">
348         <xsl:if test="$label != ''">
349           <xsl:copy-of select="$label"/>
350           <xsl:if test="$deflabel = 'number' and not(label)">
351             <xsl:value-of select="$autotoc.label.separator"/>
352           </xsl:if>
353           <xsl:text> </xsl:text>
354         </xsl:if>
355         <xsl:copy-of select="$firstchunk"/>
356       </fo:basic-link>
357     </fo:inline>
358     <fo:inline keep-together.within-line="always">
359       <xsl:text> </xsl:text>
360       <fo:leader leader-pattern="dots"
361                  leader-pattern-width="3pt"
362                  leader-alignment="reference-area"
363                  keep-with-next.within-line="always"/>
364       <xsl:text> </xsl:text> 
365       <fo:basic-link internal-destination="{$id}">
366         <fo:page-number-citation ref-id="{$id}"/>
367       </fo:basic-link>
368     </fo:inline>
369   </fo:block>
370
371 </xsl:template>
372
373 <!-- ==================================================================== -->
374
375 <xsl:template match="book|setindex" mode="toc">
376   <xsl:param name="toc-context" select="."/>
377
378   <xsl:variable name="id">
379     <xsl:call-template name="object.id"/>
380   </xsl:variable>
381
382   <xsl:variable name="cid">
383     <xsl:call-template name="object.id">
384       <xsl:with-param name="object" select="$toc-context"/>
385     </xsl:call-template>
386   </xsl:variable>
387
388   <xsl:call-template name="toc.line">
389     <xsl:with-param name="toc-context" select="$toc-context"/>
390   </xsl:call-template>
391
392   <xsl:variable name="nodes" select="glossary|bibliography|preface|chapter
393                                      |reference|part|article|appendix|index"/>
394
395   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
396
397   <xsl:if test="$toc.section.depth > 0 
398                 and $toc.max.depth > $depth.from.context
399                 and $nodes">
400     <fo:block id="toc.{$cid}.{$id}">
401       <xsl:attribute name="margin-{$direction.align.start}">
402         <xsl:call-template name="set.toc.indent"/>
403       </xsl:attribute>
404
405       <xsl:apply-templates select="$nodes" mode="toc">
406         <xsl:with-param name="toc-context" select="$toc-context"/>
407       </xsl:apply-templates>
408     </fo:block>
409   </xsl:if>
410 </xsl:template>
411
412 <xsl:template match="set" mode="toc">
413   <xsl:param name="toc-context" select="."/>
414
415   <xsl:variable name="id">
416     <xsl:call-template name="object.id"/>
417   </xsl:variable>
418
419   <xsl:variable name="cid">
420     <xsl:call-template name="object.id">
421       <xsl:with-param name="object" select="$toc-context"/>
422     </xsl:call-template>
423   </xsl:variable>
424
425   <xsl:call-template name="toc.line">
426     <xsl:with-param name="toc-context" select="$toc-context"/>
427   </xsl:call-template>
428
429   <xsl:variable name="nodes" select="set|book|setindex"/>
430
431   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
432
433   <xsl:if test="$toc.section.depth > 0 
434                 and $toc.max.depth > $depth.from.context
435                 and $nodes">
436     <fo:block id="toc.{$cid}.{$id}">
437       <xsl:attribute name="margin-{$direction.align.start}">
438         <xsl:call-template name="set.toc.indent"/>
439       </xsl:attribute>
440       
441       <xsl:apply-templates select="$nodes" mode="toc">
442         <xsl:with-param name="toc-context" select="$toc-context"/>
443       </xsl:apply-templates>
444     </fo:block>
445   </xsl:if>
446 </xsl:template>
447
448 <xsl:template match="part" mode="toc">
449   <xsl:param name="toc-context" select="."/>
450
451   <xsl:variable name="id">
452     <xsl:call-template name="object.id"/>
453   </xsl:variable>
454
455   <xsl:variable name="cid">
456     <xsl:call-template name="object.id">
457       <xsl:with-param name="object" select="$toc-context"/>
458     </xsl:call-template>
459   </xsl:variable>
460
461   <xsl:call-template name="toc.line">
462     <xsl:with-param name="toc-context" select="$toc-context"/>
463   </xsl:call-template>
464
465   <xsl:variable name="nodes" select="chapter|appendix|preface|reference|
466                                      refentry|article|index|glossary|
467                                      bibliography"/>
468
469   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
470
471   <xsl:if test="$toc.section.depth > 0 
472                 and $toc.max.depth > $depth.from.context
473                 and $nodes">
474     <fo:block id="toc.{$cid}.{$id}">
475       <xsl:attribute name="margin-{$direction.align.start}">
476         <xsl:call-template name="set.toc.indent"/>
477       </xsl:attribute>
478       
479       <xsl:apply-templates select="$nodes" mode="toc">
480         <xsl:with-param name="toc-context" select="$toc-context"/>
481       </xsl:apply-templates>
482     </fo:block>
483   </xsl:if>
484 </xsl:template>
485
486 <xsl:template match="reference" mode="toc">
487   <xsl:param name="toc-context" select="."/>
488
489   <xsl:variable name="id">
490     <xsl:call-template name="object.id"/>
491   </xsl:variable>
492
493   <xsl:variable name="cid">
494     <xsl:call-template name="object.id">
495       <xsl:with-param name="object" select="$toc-context"/>
496     </xsl:call-template>
497   </xsl:variable>
498
499   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
500
501   <xsl:call-template name="toc.line">
502     <xsl:with-param name="toc-context" select="$toc-context"/>
503   </xsl:call-template>
504
505   <xsl:if test="$toc.section.depth > 0
506                 and $toc.max.depth > $depth.from.context
507                 and refentry">
508     <fo:block id="toc.{$cid}.{$id}">
509       <xsl:attribute name="margin-{$direction.align.start}">
510         <xsl:call-template name="set.toc.indent"/>
511       </xsl:attribute>
512               
513       <xsl:apply-templates select="refentry" mode="toc">
514         <xsl:with-param name="toc-context" select="$toc-context"/>
515       </xsl:apply-templates>
516     </fo:block>
517   </xsl:if>
518 </xsl:template>
519
520 <xsl:template match="refentry" mode="toc">
521   <xsl:param name="toc-context" select="."/>
522
523   <xsl:call-template name="toc.line">
524     <xsl:with-param name="toc-context" select="$toc-context"/>
525   </xsl:call-template>
526 </xsl:template>
527
528 <xsl:template match="preface|chapter|appendix|article"
529               mode="toc">
530   <xsl:param name="toc-context" select="."/>
531
532   <xsl:variable name="id">
533     <xsl:call-template name="object.id"/>
534   </xsl:variable>
535
536   <xsl:variable name="cid">
537     <xsl:call-template name="object.id">
538       <xsl:with-param name="object" select="$toc-context"/>
539     </xsl:call-template>
540   </xsl:variable>
541
542   <xsl:call-template name="toc.line">
543     <xsl:with-param name="toc-context" select="$toc-context"/>
544   </xsl:call-template>
545
546   <xsl:variable name="nodes" select="section|sect1
547                                      |qandaset[$qanda.in.toc != 0]
548                                      |simplesect[$simplesect.in.toc != 0]
549                                      |refentry|appendix"/>
550
551   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
552
553   <xsl:if test="$toc.section.depth > 0 
554                 and $toc.max.depth > $depth.from.context
555                 and $nodes">
556     <fo:block id="toc.{$cid}.{$id}">
557       <xsl:attribute name="margin-{$direction.align.start}">
558         <xsl:call-template name="set.toc.indent"/>
559       </xsl:attribute>
560               
561       <xsl:apply-templates select="$nodes" mode="toc">
562         <xsl:with-param name="toc-context" select="$toc-context"/>
563       </xsl:apply-templates>
564     </fo:block>
565   </xsl:if>
566 </xsl:template>
567
568 <xsl:template match="sect1" mode="toc">
569   <xsl:param name="toc-context" select="."/>
570
571   <xsl:variable name="id">
572     <xsl:call-template name="object.id"/>
573   </xsl:variable>
574
575   <xsl:variable name="cid">
576     <xsl:call-template name="object.id">
577       <xsl:with-param name="object" select="$toc-context"/>
578     </xsl:call-template>
579   </xsl:variable>
580
581   <xsl:call-template name="toc.line">
582     <xsl:with-param name="toc-context" select="$toc-context"/>
583   </xsl:call-template>
584
585   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
586
587   <xsl:if test="$toc.section.depth > 1 
588                 and $toc.max.depth > $depth.from.context
589                 and sect2">
590     <fo:block id="toc.{$cid}.{$id}">
591       <xsl:attribute name="margin-{$direction.align.start}">
592         <xsl:call-template name="set.toc.indent"/>
593       </xsl:attribute>
594               
595       <xsl:apply-templates select="sect2|qandaset[$qanda.in.toc != 0]" 
596                            mode="toc">
597         <xsl:with-param name="toc-context" select="$toc-context"/>
598       </xsl:apply-templates>
599     </fo:block>
600   </xsl:if>
601 </xsl:template>
602
603 <xsl:template match="sect2" mode="toc">
604   <xsl:param name="toc-context" select="."/>
605
606   <xsl:variable name="id">
607     <xsl:call-template name="object.id"/>
608   </xsl:variable>
609
610   <xsl:variable name="cid">
611     <xsl:call-template name="object.id">
612       <xsl:with-param name="object" select="$toc-context"/>
613     </xsl:call-template>
614   </xsl:variable>
615
616   <xsl:call-template name="toc.line">
617     <xsl:with-param name="toc-context" select="$toc-context"/>
618   </xsl:call-template>
619
620   <xsl:variable name="reldepth"
621                 select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
622
623   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
624
625   <xsl:if test="$toc.section.depth > 2 
626                 and $toc.max.depth > $depth.from.context
627                 and sect3">
628     <fo:block id="toc.{$cid}.{$id}">
629       <xsl:attribute name="margin-{$direction.align.start}">
630         <xsl:call-template name="set.toc.indent">
631           <xsl:with-param name="reldepth" select="$reldepth"/>
632         </xsl:call-template>
633       </xsl:attribute>
634               
635       <xsl:apply-templates select="sect3|qandaset[$qanda.in.toc != 0]" 
636                            mode="toc">
637         <xsl:with-param name="toc-context" select="$toc-context"/>
638       </xsl:apply-templates>
639     </fo:block>
640   </xsl:if>
641 </xsl:template>
642
643 <xsl:template match="sect3" mode="toc">
644   <xsl:param name="toc-context" select="."/>
645
646   <xsl:variable name="id">
647     <xsl:call-template name="object.id"/>
648   </xsl:variable>
649
650   <xsl:variable name="cid">
651     <xsl:call-template name="object.id">
652       <xsl:with-param name="object" select="$toc-context"/>
653     </xsl:call-template>
654   </xsl:variable>
655
656   <xsl:call-template name="toc.line">
657     <xsl:with-param name="toc-context" select="$toc-context"/>
658   </xsl:call-template>
659
660   <xsl:variable name="reldepth"
661                 select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
662
663   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
664
665   <xsl:if test="$toc.section.depth > 3 
666                 and $toc.max.depth > $depth.from.context
667                 and sect4">
668     <fo:block id="toc.{$cid}.{$id}">
669       <xsl:attribute name="margin-{$direction.align.start}">
670         <xsl:call-template name="set.toc.indent">
671           <xsl:with-param name="reldepth" select="$reldepth"/>
672         </xsl:call-template>
673       </xsl:attribute>
674               
675       <xsl:apply-templates select="sect4|qandaset[$qanda.in.toc != 0]" 
676                            mode="toc">
677         <xsl:with-param name="toc-context" select="$toc-context"/>
678       </xsl:apply-templates>
679     </fo:block>
680   </xsl:if>
681 </xsl:template>
682
683 <xsl:template match="sect4" mode="toc">
684   <xsl:param name="toc-context" select="."/>
685
686   <xsl:variable name="id">
687     <xsl:call-template name="object.id"/>
688   </xsl:variable>
689
690   <xsl:variable name="cid">
691     <xsl:call-template name="object.id">
692       <xsl:with-param name="object" select="$toc-context"/>
693     </xsl:call-template>
694   </xsl:variable>
695
696   <xsl:call-template name="toc.line">
697     <xsl:with-param name="toc-context" select="$toc-context"/>
698   </xsl:call-template>
699
700   <xsl:variable name="reldepth"
701                 select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
702
703   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
704
705   <xsl:if test="$toc.section.depth > 4 
706                 and $toc.max.depth > $depth.from.context
707                 and sect5">
708     <fo:block id="toc.{$cid}.{$id}">
709       <xsl:attribute name="margin-{$direction.align.start}">
710         <xsl:call-template name="set.toc.indent">
711           <xsl:with-param name="reldepth" select="$reldepth"/>
712         </xsl:call-template>
713       </xsl:attribute>
714               
715       <xsl:apply-templates select="sect5|qandaset[$qanda.in.toc != 0]" 
716                            mode="toc">
717         <xsl:with-param name="toc-context" select="$toc-context"/>
718       </xsl:apply-templates>
719     </fo:block>
720   </xsl:if>
721 </xsl:template>
722
723 <xsl:template match="sect5|simplesect" mode="toc">
724   <xsl:param name="toc-context" select="."/>
725
726   <xsl:call-template name="toc.line">
727     <xsl:with-param name="toc-context" select="$toc-context"/>
728   </xsl:call-template>
729 </xsl:template>
730
731 <xsl:template name="set.toc.indent">
732   <xsl:param name="reldepth"/>
733
734   <xsl:variable name="depth">
735     <xsl:choose>
736       <xsl:when test="$reldepth != ''">
737         <xsl:value-of select="$reldepth"/>
738       </xsl:when>
739       <xsl:otherwise>
740         <xsl:value-of select="count(ancestor::*)"/>
741       </xsl:otherwise>
742     </xsl:choose>
743   </xsl:variable>
744
745   <xsl:choose>
746     <xsl:when test="$fop.extensions != 0 or $passivetex.extensions != 0">
747        <xsl:value-of select="concat($depth*$toc.indent.width, 'pt')"/>
748     </xsl:when>
749     <xsl:otherwise>
750       <xsl:value-of select="concat($toc.indent.width, 'pt')"/>
751     </xsl:otherwise>
752   </xsl:choose>
753 </xsl:template>
754
755
756 <xsl:template match="section" mode="toc">
757   <xsl:param name="toc-context" select="."/>
758
759   <xsl:variable name="id">
760     <xsl:call-template name="object.id"/>
761   </xsl:variable>
762
763   <xsl:variable name="cid">
764     <xsl:call-template name="object.id">
765       <xsl:with-param name="object" select="$toc-context"/>
766     </xsl:call-template>
767   </xsl:variable>
768
769   <xsl:variable name="depth" select="count(ancestor::section) + 1"/>
770   <xsl:variable name="reldepth"
771                 select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
772
773   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
774
775   <xsl:if test="$toc.section.depth &gt;= $depth">
776     <xsl:call-template name="toc.line">
777       <xsl:with-param name="toc-context" select="$toc-context"/>
778     </xsl:call-template>
779
780     <xsl:if test="$toc.section.depth > $depth 
781                   and $toc.max.depth > $depth.from.context
782                   and section">
783       <fo:block id="toc.{$cid}.{$id}">
784         <xsl:attribute name="margin-{$direction.align.start}">
785           <xsl:call-template name="set.toc.indent">
786             <xsl:with-param name="reldepth" select="$reldepth"/>
787           </xsl:call-template>
788         </xsl:attribute>
789                 
790         <xsl:apply-templates select="section|qandaset[$qanda.in.toc != 0]" 
791                            mode="toc">
792           <xsl:with-param name="toc-context" select="$toc-context"/>
793         </xsl:apply-templates>
794       </fo:block>
795     </xsl:if>
796   </xsl:if>
797 </xsl:template>
798
799 <xsl:template match="bibliography|glossary"
800               mode="toc">
801   <xsl:param name="toc-context" select="."/>
802
803   <xsl:call-template name="toc.line">
804     <xsl:with-param name="toc-context" select="$toc-context"/>
805   </xsl:call-template>
806 </xsl:template>
807
808 <xsl:template match="index" mode="toc">
809   <xsl:param name="toc-context" select="."/>
810
811   <xsl:if test="* or $generate.index != 0">
812     <xsl:call-template name="toc.line">
813     <xsl:with-param name="toc-context" select="$toc-context"/>
814   </xsl:call-template>
815   </xsl:if>
816 </xsl:template>
817
818 <xsl:template match="title" mode="toc">
819   <xsl:apply-templates/>
820 </xsl:template>
821
822 <!-- ==================================================================== -->
823
824 <xsl:template name="list.of.titles">
825   <xsl:param name="titles" select="'table'"/>
826   <xsl:param name="nodes" select=".//table"/>
827   <xsl:param name="toc-context" select="."/>
828
829   <xsl:variable name="id">
830     <xsl:call-template name="object.id"/>
831   </xsl:variable>
832
833   <xsl:if test="$nodes">
834     <fo:block id="lot...{$titles}...{$id}">
835       <xsl:choose>
836         <xsl:when test="$titles='table'">
837           <xsl:call-template name="list.of.tables.titlepage"/>
838         </xsl:when>
839         <xsl:when test="$titles='figure'">
840           <xsl:call-template name="list.of.figures.titlepage"/>
841         </xsl:when>
842         <xsl:when test="$titles='equation'">
843           <xsl:call-template name="list.of.equations.titlepage"/>
844         </xsl:when>
845         <xsl:when test="$titles='example'">
846           <xsl:call-template name="list.of.examples.titlepage"/>
847         </xsl:when>
848         <xsl:when test="$titles='procedure'">
849           <xsl:call-template name="list.of.procedures.titlepage"/>
850         </xsl:when>
851         <xsl:otherwise>
852           <xsl:call-template name="list.of.unknowns.titlepage"/>
853         </xsl:otherwise>
854       </xsl:choose>
855       <xsl:apply-templates select="$nodes" mode="toc">
856         <xsl:with-param name="toc-context" select="$toc-context"/>
857       </xsl:apply-templates>
858     </fo:block>
859   </xsl:if>
860 </xsl:template>
861
862 <xsl:template match="figure|table|example|equation|procedure" mode="toc">
863   <xsl:param name="toc-context" select="."/>
864   <xsl:call-template name="toc.line">
865     <xsl:with-param name="toc-context" select="$toc-context"/>
866   </xsl:call-template>
867 </xsl:template>
868
869 <!-- ==================================================================== -->
870
871 <!-- qandaset handled like a section when qanda.in.toc is set -->
872 <xsl:template match="qandaset" mode="toc">
873   <xsl:param name="toc-context" select="."/>
874
875   <xsl:variable name="id">
876     <xsl:call-template name="object.id"/>
877   </xsl:variable>
878
879   <xsl:variable name="cid">
880     <xsl:call-template name="object.id">
881       <xsl:with-param name="object" select="$toc-context"/>
882     </xsl:call-template>
883   </xsl:variable>
884
885   <xsl:variable name="depth" select="count(ancestor::section) + 1"/>
886   <xsl:variable name="reldepth"
887                 select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
888
889   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
890
891   <xsl:if test="$toc.section.depth &gt;= $depth">
892     <xsl:call-template name="toc.line">
893       <xsl:with-param name="toc-context" select="$toc-context"/>
894     </xsl:call-template>
895
896     <xsl:if test="$toc.section.depth > $depth 
897                   and $toc.max.depth > $depth.from.context
898                   and (child::qandadiv or child::qandaentry)">
899       <fo:block id="toc.{$cid}.{$id}">
900         <xsl:attribute name="margin-{$direction.align.start}">
901           <xsl:call-template name="set.toc.indent">
902             <xsl:with-param name="reldepth" select="$reldepth"/>
903           </xsl:call-template>
904         </xsl:attribute>
905                 
906         <xsl:apply-templates select="qandadiv|qandaentry" mode="toc">
907           <xsl:with-param name="toc-context" select="$toc-context"/>
908         </xsl:apply-templates>
909       </fo:block>
910     </xsl:if>
911   </xsl:if>
912 </xsl:template>
913
914 </xsl:stylesheet>
915