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<!-- FIXME: in the contexts where <toc> can occur, I think it's always
19     the case that a page-sequence is required. Is that true? -->
20
21<xsl:template match="toc">
22  <xsl:variable name="master-name">
23    <xsl:call-template name="select.pagemaster"/>
24  </xsl:variable>
25
26  <xsl:choose>
27    <xsl:when test="*">
28      <xsl:if test="$process.source.toc != 0">
29        <!-- if the toc isn't empty, process it -->
30        <fo:page-sequence hyphenate="{$hyphenate}"
31                          master-name="{$master-name}">
32          <xsl:attribute name="language">
33            <xsl:call-template name="l10n.language"/>
34          </xsl:attribute>
35          <xsl:if test="$double.sided != 0">
36            <xsl:attribute name="force-page-count">end-on-even</xsl:attribute>
37          </xsl:if>
38
39          <xsl:apply-templates select="." mode="running.head.mode">
40            <xsl:with-param name="master-name" select="$master-name"/>
41          </xsl:apply-templates>
42          <xsl:apply-templates select="." mode="running.foot.mode">
43            <xsl:with-param name="master-name" select="$master-name"/>
44          </xsl:apply-templates>
45
46          <fo:flow flow-name="xsl-region-body">
47            <fo:block xsl:use-attribute-sets="toc.margin.properties">
48              <xsl:call-template name="table.of.contents.titlepage"/>
49              <xsl:apply-templates/>
50            </fo:block>
51          </fo:flow>
52        </fo:page-sequence>
53      </xsl:if>
54    </xsl:when>
55    <xsl:otherwise>
56      <xsl:if test="$process.empty.source.toc != 0">
57        <fo:page-sequence hyphenate="{$hyphenate}"
58                          master-name="{$master-name}">
59          <xsl:attribute name="language">
60            <xsl:call-template name="l10n.language"/>
61          </xsl:attribute>
62          <xsl:if test="$double.sided != 0">
63            <xsl:attribute name="force-page-count">end-on-even</xsl:attribute>
64          </xsl:if>
65
66          <xsl:apply-templates select="." mode="running.head.mode">
67            <xsl:with-param name="master-name" select="$master-name"/>
68          </xsl:apply-templates>
69          <xsl:apply-templates select="." mode="running.foot.mode">
70            <xsl:with-param name="master-name" select="$master-name"/>
71          </xsl:apply-templates>
72
73          <fo:flow flow-name="xsl-region-body">
74            <xsl:choose>
75              <xsl:when test="parent::section
76                              or parent::sect1
77                              or parent::sect2
78                              or parent::sect3
79                              or parent::sect4
80                              or parent::sect5">
81                <xsl:apply-templates select="parent::*"
82                                     mode="toc.for.section"/>
83              </xsl:when>
84              <xsl:when test="parent::article">
85                <xsl:apply-templates select="parent::*"
86                                     mode="toc.for.component"/>
87              </xsl:when>
88              <xsl:when test="parent::book
89                              or parent::part">
90                <xsl:apply-templates select="parent::*"
91                                     mode="toc.for.division"/>
92              </xsl:when>
93              <xsl:when test="parent::set">
94                <xsl:apply-templates select="parent::*"
95                                     mode="toc.for.set"/>
96              </xsl:when>
97              <!-- there aren't any other contexts that allow toc -->
98              <xsl:otherwise>
99                <xsl:message>
100                  <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
101                </xsl:message>
102              </xsl:otherwise>
103            </xsl:choose>
104          </fo:flow>
105        </fo:page-sequence>
106      </xsl:if>
107    </xsl:otherwise>
108  </xsl:choose>
109</xsl:template>
110
111<xsl:template match="tocpart|tocchap
112                     |toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
113  <xsl:apply-templates select="tocentry"/>
114  <xsl:if test="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
115    <fo:block start-indent="{count(ancestor::*)*2}pc">
116      <xsl:apply-templates select="tocchap|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5"/>
117    </fo:block>
118  </xsl:if>
119</xsl:template>
120
121<xsl:template match="tocentry|tocfront|tocback">
122  <fo:block text-align-last="justify"
123            end-indent="2pc"
124            last-line-end-indent="-2pc">
125    <fo:inline keep-with-next.within-line="always">
126      <xsl:choose>
127        <xsl:when test="@linkend">
128          <fo:basic-link internal-destination="{@linkend}">
129            <xsl:apply-templates/>
130          </fo:basic-link>
131        </xsl:when>
132        <xsl:otherwise>
133          <xsl:apply-templates/>
134        </xsl:otherwise>
135      </xsl:choose>
136    </fo:inline>
137
138    <xsl:choose>
139      <xsl:when test="@linkend">
140        <fo:inline keep-together.within-line="always">
141          <xsl:text> </xsl:text>
142          <fo:leader leader-pattern="dots"
143                     keep-with-next.within-line="always"/>
144          <xsl:text> </xsl:text>
145          <fo:basic-link internal-destination="{@linkend}">
146            <xsl:choose>
147              <xsl:when test="@pagenum">
148                <xsl:value-of select="@pagenum"/>
149              </xsl:when>
150              <xsl:otherwise>
151                <fo:page-number-citation ref-id="{@linkend}"/>
152              </xsl:otherwise>
153            </xsl:choose>
154          </fo:basic-link>
155        </fo:inline>
156      </xsl:when>
157      <xsl:when test="@pagenum">
158        <fo:inline keep-together.within-line="always">
159          <xsl:text> </xsl:text>
160          <fo:leader leader-pattern="dots"
161                     keep-with-next.within-line="always"/>
162          <xsl:text> </xsl:text>
163          <xsl:value-of select="@pagenum"/>
164        </fo:inline>
165      </xsl:when>
166      <xsl:otherwise>
167        <!-- just the leaders, what else can I do? -->
168        <fo:inline keep-together.within-line="always">
169          <xsl:text> </xsl:text>
170          <fo:leader leader-pattern="space"
171                     keep-with-next.within-line="always"/>
172        </fo:inline>
173      </xsl:otherwise>
174    </xsl:choose>
175  </fo:block>
176</xsl:template>
177
178<!-- ==================================================================== -->
179
180<xsl:template match="*" mode="toc.for.section">
181<!--
182  <xsl:call-template name="section.toc"/>
183-->
184</xsl:template>
185
186<xsl:template match="*" mode="toc.for.component">
187  <xsl:call-template name="component.toc"/>
188</xsl:template>
189
190<xsl:template match="*" mode="toc.for.section">
191<!--
192  <xsl:call-template name="section.toc"/>
193-->
194</xsl:template>
195
196<xsl:template match="*" mode="toc.for.division">
197  <xsl:call-template name="division.toc"/>
198</xsl:template>
199
200<xsl:template match="*" mode="toc.for.set">
201<!--
202  <xsl:call-template name="set.toc"/>
203-->
204</xsl:template>
205
206<!-- ==================================================================== -->
207
208<xsl:template match="lot|lotentry">
209</xsl:template>
210
211</xsl:stylesheet>
212