summaryrefslogtreecommitdiff
path: root/doc/editor_configs/serna/scons/docbook-xsl-serna/toc.xsl
blob: 27dbdf4a82bf46e936f1b000e7c4b0018558227b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:xse="http://www.syntext.com/Extensions/XSLT-1.0"
                xmlns:dtm="http://syntext.com/Extensions/DocumentTypeMetadata-1.0"
                extension-element-prefixes="dtm xse"
                version='1.0'>

<dtm:doc dtm:idref="set.toc"/>
<xsl:template name="set.toc" dtm:id="set.toc">
  <xsl:param name="toc-context" select="."/>
  <xsl:variable name="nodes" select="book|setindex"/>

  <fo:block 
    xsl:use-attribute-sets="title.content.properties component.title.properties">
    <xsl:call-template name="gentext">
      <xsl:with-param name="key" select="'tableofcontents'"/>
    </xsl:call-template>
  </fo:block>

  <xsl:if test="$nodes">
    <fo:block xsl:use-attribute-sets="toc.margin.properties">
      <xsl:apply-templates select="$nodes" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="division.toc"/>
<xsl:template name="division.toc" dtm:id="division.toc">
  <xsl:param name="toc-context" select="."/>
  <xsl:variable name="nodes"
                select="$toc-context/part
                        |$toc-context/reference
                        |$toc-context/preface
                        |$toc-context/chapter
                        |$toc-context/appendix
                        |$toc-context/article
                        |$toc-context/bibliography
                        |$toc-context/glossary
                        |$toc-context/index"/>
  <fo:block 
    xsl:use-attribute-sets="title.content.properties component.title.properties">
      <fo:inline>
        <xsl:call-template name="gentext">
          <xsl:with-param name="key" select="'tableofcontents'"/>
        </xsl:call-template>
      </fo:inline>
  </fo:block>

  <xsl:if test="$nodes">
    <fo:block 
      xsl:use-attribute-sets="toc.margin.properties">
      <xsl:apply-templates select="$nodes" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="component.toc"/>
<xsl:template name="component.toc" dtm:id="component.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:variable name="nodes" select="section|sect1|refentry
                                     |article|bibliography|glossary
                                     |appendix"/>
  <!-- fo:block 
    xsl:use-attribute-sets="title.content.properties section.title.level1.properties">
    <xsl:call-template name="gentext">
      <xsl:with-param name="key" select="'toc'"/>
    </xsl:call-template>
  </fo:block -->

  <xsl:if test="$nodes">
    <fo:block xsl:use-attribute-sets="toc.margin.properties">
      <xsl:apply-templates select="$nodes" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="toc.line"/>
<xsl:template name="toc.line" dtm:id="toc.line">
  <xsl:variable name="label">
    <xsl:apply-templates select="." mode="label.markup" xse:apply-serna-fold-template="false"/>
  </xsl:variable>
  <xsl:variable name="is.component">
    <xsl:call-template name="is.component">
    </xsl:call-template>
  </xsl:variable>

  <fo:block 
    end-indent="{$toc.indent.width}pt">
    <xsl:if test="$is.component = 1 or 
                  local-name(.) = 'part' or local-name(.) = 'book'">
      <xsl:attribute name="font-weight">
        <xsl:text>bold</xsl:text>
      </xsl:attribute>
    </xsl:if>
    <fo:inline>
      <xsl:if test="$label != ''">
        <xsl:copy-of select="$label"/>
        <xsl:value-of select="$autotoc.label.separator"/>
      </xsl:if>
      <xsl:apply-templates select="." mode="title.markup" xse:apply-serna-fold-template="false"/>
    </fo:inline>
  </fo:block>
</xsl:template>

<dtm:doc dtm:idref="bs.toc"/>
<xsl:template match="book|setindex" mode="toc" dtm:id="bs.toc">
  <xsl:param name="toc-context" select="."/>
  <xsl:call-template name="toc.line"/>

  <xsl:variable name="nodes" select="glossary|bibliography|preface|chapter
                                     |reference|part|article|appendix|index"/>

  <xsl:if test="$toc.section.depth &gt; 0 and $nodes">
    <fo:block start-indent="{count(ancestor::*)*$toc.indent.width}pt">
      <xsl:apply-templates select="$nodes" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="part.toc"/>
<xsl:template match="part" mode="toc" dtm:id="part.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:variable name="nodes" select="chapter|appendix|preface|reference|article"/>

  <xsl:if test="$toc.section.depth &gt; 0 and $nodes">
    <fo:block start-indent="{count(ancestor::*)*$toc.indent.width}pt">
      <xsl:apply-templates select="$nodes" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="rb.toc"/>
<xsl:template match="refentry|book" mode="toc" dtm:id="rb.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>
</xsl:template>

<dtm:doc dtm:idref="pcaa.toc"/>
<xsl:template match="preface|chapter|appendix|article"
              mode="toc" dtm:id="pcaa.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:variable name="nodes" select="section|sect1"/>

  <xsl:if test="$toc.section.depth &gt; 0 and $nodes">
    <fo:block start-indent="{count(ancestor::*)*$toc.indent.width}pt">
      <xsl:apply-templates select="$nodes" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="sect1.toc"/>
<xsl:template match="sect1" mode="toc" dtm:id="sect1.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:if test="$toc.section.depth &gt; 1 and sect2">
    <fo:block 
      start-indent="{count(ancestor::*)*$toc.indent.width}pt">
      <xsl:apply-templates select="sect2" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="sect2.toc"/>
<xsl:template match="sect2" mode="toc" dtm:id="sect2.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:variable name="reldepth"
                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>

  <xsl:if test="$toc.section.depth &gt; 2 and sect3">
    <fo:block
      start-indent="{$reldepth*$toc.indent.width}pt">
      <xsl:apply-templates select="sect3" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="sect3.toc"/>
<xsl:template match="sect3" mode="toc" dtm:id="sect3.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:variable name="reldepth"
                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>

  <xsl:if test="$toc.section.depth &gt; 3 and sect4">
    <fo:block
      start-indent="{$reldepth*$toc.indent.width}pt">
      <xsl:apply-templates select="sect4" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="sect4.toc"/>
<xsl:template match="sect4" mode="toc" dtm:id="sect4.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:variable name="reldepth"
                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>

  <xsl:if test="$toc.section.depth &gt; 4 and sect5">
    <fo:block
      start-indent="{$reldepth*$toc.indent.width}pt">
      <xsl:apply-templates select="sect5" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="sect5.toc"/>
<xsl:template match="sect5" mode="toc" dtm:id="sect5.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>
</xsl:template>

<dtm:doc dtm:idref="section.toc"/>
<xsl:template match="section" mode="toc" dtm:id="section.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:variable name="depth" select="count(ancestor::section) + 1"/>
  <xsl:variable name="reldepth"
                select="count(ancestor::*)-count($toc-context/ancestor::*)"/>

  <xsl:if test="$toc.section.depth &gt;= $depth">
    <xsl:call-template name="toc.line"/>

    <xsl:if test="$toc.section.depth &gt; $depth and section">
      <fo:block
        start-indent="{$reldepth*$toc.indent.width}pt">
        <xsl:apply-templates select="section" mode="toc" xse:apply-serna-fold-template="false">
          <xsl:with-param name="toc-context" select="$toc-context"/>
        </xsl:apply-templates>
      </fo:block>
    </xsl:if>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="bg.toc"/>
<xsl:template match="bibliography|glossary"
              mode="toc" dtm:id="bg.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>
</xsl:template>

<dtm:doc dtm:idref="reference.toc"/>
<xsl:template match="reference" mode="toc" dtm:id="reference.toc">
  <xsl:param name="toc-context" select="."/>

  <xsl:call-template name="toc.line"/>

  <xsl:if test="$toc.section.depth &gt; 0 and refentry">
    <fo:block 
              start-indent="{count(ancestor::*)*$toc.indent.width}pt">
      <xsl:apply-templates select="refentry" mode="toc" xse:apply-serna-fold-template="false">
        <xsl:with-param name="toc-context" select="$toc-context"/>
      </xsl:apply-templates>
    </fo:block>
  </xsl:if>
</xsl:template>

<dtm:doc dtm:idref="title.toc"/>
<xsl:template match="title" mode="toc" dtm:id="title.toc">
  <xsl:apply-templates xse:apply-serna-fold-template="false"/>
</xsl:template>

</xsl:stylesheet>