]> git.stg.codes - stg.git/blob - doc/xslt/fo/index.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / fo / index.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY % common.entities SYSTEM "../common/entities.ent">
4 %common.entities;
5 ]>
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
8                 xmlns:rx="http://www.renderx.com/XSL/Extensions"
9                 version='1.0'>
10
11 <!-- ********************************************************************
12      $Id: index.xsl 8724 2010-07-15 07:53:27Z kosek $
13      ********************************************************************
14
15      This file is part of the XSL DocBook Stylesheet distribution.
16      See ../README or http://docbook.sf.net/release/xsl/current/ for
17      copyright and other information.
18
19      ******************************************************************** -->
20
21 <!-- ==================================================================== -->
22
23 <xsl:template match="index">
24   <xsl:variable name="id">
25     <xsl:call-template name="object.id"/>
26   </xsl:variable>
27
28  <xsl:if test="$generate.index != 0">
29   <xsl:choose>
30     <xsl:when test="$make.index.markup != 0">
31       <fo:block>
32         <xsl:call-template name="generate-index-markup">
33           <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
34         </xsl:call-template>
35       </fo:block>
36     </xsl:when>
37     <xsl:otherwise>
38       <fo:block id="{$id}">
39         <xsl:call-template name="index.titlepage"/>
40       </fo:block>
41       <xsl:apply-templates/>
42       <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
43         <xsl:call-template name="generate-index">
44           <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
45         </xsl:call-template>
46       </xsl:if>
47     </xsl:otherwise>
48   </xsl:choose>
49  </xsl:if>
50 </xsl:template>
51
52 <xsl:template match="book/index|part/index">
53   <xsl:variable name="id">
54     <xsl:call-template name="object.id"/>
55   </xsl:variable>
56
57  <xsl:if test="$generate.index != 0">
58   <xsl:variable name="master-reference">
59     <xsl:call-template name="select.pagemaster">
60       <xsl:with-param name="pageclass">
61         <xsl:if test="$make.index.markup != 0">body</xsl:if>
62       </xsl:with-param>
63     </xsl:call-template>
64   </xsl:variable>
65
66   <fo:page-sequence hyphenate="{$hyphenate}"
67                     master-reference="{$master-reference}">
68     <xsl:attribute name="language">
69       <xsl:call-template name="l10n.language"/>
70     </xsl:attribute>
71     <xsl:attribute name="format">
72       <xsl:call-template name="page.number.format">
73         <xsl:with-param name="master-reference" select="$master-reference"/>
74       </xsl:call-template>
75     </xsl:attribute>
76
77     <xsl:attribute name="initial-page-number">
78       <xsl:call-template name="initial.page.number">
79         <xsl:with-param name="master-reference" select="$master-reference"/>
80       </xsl:call-template>
81     </xsl:attribute>
82
83     <xsl:attribute name="force-page-count">
84       <xsl:call-template name="force.page.count">
85         <xsl:with-param name="master-reference" select="$master-reference"/>
86       </xsl:call-template>
87     </xsl:attribute>
88
89     <xsl:attribute name="hyphenation-character">
90       <xsl:call-template name="gentext">
91         <xsl:with-param name="key" select="'hyphenation-character'"/>
92       </xsl:call-template>
93     </xsl:attribute>
94     <xsl:attribute name="hyphenation-push-character-count">
95       <xsl:call-template name="gentext">
96         <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
97       </xsl:call-template>
98     </xsl:attribute>
99     <xsl:attribute name="hyphenation-remain-character-count">
100       <xsl:call-template name="gentext">
101         <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
102       </xsl:call-template>
103     </xsl:attribute>
104
105     <xsl:apply-templates select="." mode="running.head.mode">
106       <xsl:with-param name="master-reference" select="$master-reference"/>
107     </xsl:apply-templates>
108     <xsl:apply-templates select="." mode="running.foot.mode">
109       <xsl:with-param name="master-reference" select="$master-reference"/>
110     </xsl:apply-templates>
111
112     <fo:flow flow-name="xsl-region-body">
113       <xsl:call-template name="set.flow.properties">
114         <xsl:with-param name="element" select="local-name(.)"/>
115         <xsl:with-param name="master-reference" select="$master-reference"/>
116       </xsl:call-template>
117
118       <fo:block id="{$id}"
119                 xsl:use-attribute-sets="component.titlepage.properties">
120         <xsl:call-template name="index.titlepage"/>
121       </fo:block>
122       <xsl:apply-templates/>
123       <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
124
125         <xsl:choose>
126           <xsl:when test="$make.index.markup != 0">
127             <fo:block wrap-option='no-wrap'
128                       white-space-collapse='false'
129                       xsl:use-attribute-sets="monospace.verbatim.properties"
130                       linefeed-treatment="preserve">
131               <xsl:call-template name="generate-index-markup">
132                 <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
133               </xsl:call-template>
134             </fo:block>
135           </xsl:when>
136           <xsl:when test="indexentry|indexdiv/indexentry">
137             <xsl:apply-templates/>
138           </xsl:when>
139           <xsl:otherwise>
140             <xsl:call-template name="generate-index">
141               <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
142             </xsl:call-template>
143           </xsl:otherwise>
144         </xsl:choose>
145       </xsl:if>
146     </fo:flow>
147   </fo:page-sequence>
148  </xsl:if>
149 </xsl:template>
150
151 <xsl:template match="setindex">
152   <xsl:variable name="id">
153     <xsl:call-template name="object.id"/>
154   </xsl:variable>
155
156  <xsl:if test="$generate.index != 0">
157   <xsl:variable name="master-reference">
158     <xsl:call-template name="select.pagemaster">
159       <xsl:with-param name="pageclass">
160         <xsl:choose>
161           <xsl:when test="$make.index.markup != 0">body</xsl:when>
162           <xsl:otherwise>index</xsl:otherwise>
163         </xsl:choose>
164       </xsl:with-param>
165     </xsl:call-template>
166   </xsl:variable>
167
168   <fo:page-sequence hyphenate="{$hyphenate}"
169                     master-reference="{$master-reference}">
170     <xsl:attribute name="language">
171       <xsl:call-template name="l10n.language"/>
172     </xsl:attribute>
173     <xsl:attribute name="format">
174       <xsl:call-template name="page.number.format">
175         <xsl:with-param name="master-reference" select="$master-reference"/>
176       </xsl:call-template>
177     </xsl:attribute>
178
179     <xsl:attribute name="initial-page-number">
180       <xsl:call-template name="initial.page.number">
181         <xsl:with-param name="master-reference" select="$master-reference"/>
182       </xsl:call-template>
183     </xsl:attribute>
184
185     <xsl:attribute name="force-page-count">
186       <xsl:call-template name="force.page.count">
187         <xsl:with-param name="master-reference" select="$master-reference"/>
188       </xsl:call-template>
189     </xsl:attribute>
190
191     <xsl:attribute name="hyphenation-character">
192       <xsl:call-template name="gentext">
193         <xsl:with-param name="key" select="'hyphenation-character'"/>
194       </xsl:call-template>
195     </xsl:attribute>
196     <xsl:attribute name="hyphenation-push-character-count">
197       <xsl:call-template name="gentext">
198         <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
199       </xsl:call-template>
200     </xsl:attribute>
201     <xsl:attribute name="hyphenation-remain-character-count">
202       <xsl:call-template name="gentext">
203         <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
204       </xsl:call-template>
205     </xsl:attribute>
206
207     <xsl:apply-templates select="." mode="running.head.mode">
208       <xsl:with-param name="master-reference" select="$master-reference"/>
209     </xsl:apply-templates>
210     <xsl:apply-templates select="." mode="running.foot.mode">
211       <xsl:with-param name="master-reference" select="$master-reference"/>
212     </xsl:apply-templates>
213
214     <fo:flow flow-name="xsl-region-body">
215       <xsl:call-template name="set.flow.properties">
216         <xsl:with-param name="element" select="local-name(.)"/>
217         <xsl:with-param name="master-reference" select="$master-reference"/>
218       </xsl:call-template>
219
220       <fo:block id="{$id}">
221         <xsl:call-template name="setindex.titlepage"/>
222       </fo:block>
223       <xsl:apply-templates/>
224       <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
225
226         <xsl:choose>
227           <xsl:when test="$make.index.markup != 0">
228             <fo:block wrap-option='no-wrap'
229                       white-space-collapse='false'
230                       xsl:use-attribute-sets="monospace.verbatim.properties"
231                       linefeed-treatment="preserve">
232               <xsl:call-template name="generate-index-markup">
233                 <xsl:with-param name="scope" select="/"/>
234               </xsl:call-template>
235             </fo:block>
236           </xsl:when>
237           <xsl:when test="indexentry|indexdiv/indexentry">
238             <xsl:apply-templates/>
239           </xsl:when>
240           <xsl:otherwise>
241             <xsl:call-template name="generate-index">
242               <xsl:with-param name="scope" select="/"/>
243             </xsl:call-template>
244           </xsl:otherwise>
245         </xsl:choose>
246       </xsl:if>
247     </fo:flow>
248   </fo:page-sequence>
249  </xsl:if>
250 </xsl:template>
251
252 <xsl:template match="index/indexinfo"></xsl:template>
253 <xsl:template match="index/info"></xsl:template>
254 <xsl:template match="index/title"></xsl:template>
255 <xsl:template match="index/subtitle"></xsl:template>
256 <xsl:template match="index/titleabbrev"></xsl:template>
257
258 <!-- ==================================================================== -->
259
260 <xsl:template name="indexdiv.title">
261   <xsl:param name="title"/>
262   <xsl:param name="titlecontent"/>
263
264   <fo:block xsl:use-attribute-sets="index.div.title.properties">
265     <xsl:choose>
266       <xsl:when test="$title">
267         <xsl:apply-templates select="." mode="object.title.markup">
268           <xsl:with-param name="allow-anchors" select="1"/>
269         </xsl:apply-templates>
270       </xsl:when>
271       <xsl:otherwise>
272         <xsl:copy-of select="$titlecontent"/>
273       </xsl:otherwise>
274     </xsl:choose>
275   </fo:block>
276 </xsl:template>
277
278 <xsl:template match="indexdiv">
279   <fo:block>
280     <xsl:call-template name="indexdiv.titlepage"/>
281     <xsl:apply-templates/>
282   </fo:block>
283 </xsl:template>
284
285 <xsl:template match="indexdiv/title"/>
286 <xsl:template match="indexdiv/subtitle"/>
287 <xsl:template match="indexdiv/titleabbrev"/>
288
289 <!-- ==================================================================== -->
290
291 <!-- Text used for distiguishing between normal and significant entries -->
292 <xsl:variable name="significant.flag">.tnacifingis</xsl:variable>
293
294 <xsl:template match="indexterm" name="indexterm">
295   <!-- Temporal workaround for bug in AXF -->
296   <xsl:variable name="wrapper.name">
297     <xsl:choose>
298       <xsl:when test="$axf.extensions != 0 or $fop1.extensions != 0">
299         <xsl:call-template name="inline.or.block"/>
300       </xsl:when>
301       <xsl:otherwise>fo:wrapper</xsl:otherwise>
302     </xsl:choose>
303   </xsl:variable>
304
305   <xsl:element name="{$wrapper.name}">
306     <xsl:attribute name="id">
307       <xsl:call-template name="object.id"/>
308     </xsl:attribute>
309     <xsl:choose>
310       <xsl:when test="$xep.extensions != 0">
311         <xsl:attribute name="rx:key">
312           <xsl:value-of select="&primary;"/>
313           <xsl:if test="@significance='preferred'"><xsl:value-of select="$significant.flag"/></xsl:if>
314           <xsl:if test="secondary">
315             <xsl:text>, </xsl:text>
316             <xsl:value-of select="&secondary;"/>
317           </xsl:if>
318           <xsl:if test="tertiary">
319             <xsl:text>, </xsl:text>
320             <xsl:value-of select="&tertiary;"/>
321           </xsl:if>
322         </xsl:attribute>
323       </xsl:when>
324       <xsl:otherwise>
325         <xsl:comment>
326           <xsl:call-template name="comment-escape-string">
327             <xsl:with-param name="string">
328               <xsl:value-of select="primary"/>
329               <xsl:if test="secondary">
330                 <xsl:text>, </xsl:text>
331                 <xsl:value-of select="secondary"/>
332               </xsl:if>
333               <xsl:if test="tertiary">
334                 <xsl:text>, </xsl:text>
335                 <xsl:value-of select="tertiary"/>
336               </xsl:if>
337             </xsl:with-param>
338           </xsl:call-template>
339         </xsl:comment>
340       </xsl:otherwise>
341     </xsl:choose>
342   </xsl:element>
343 </xsl:template>
344
345 <xsl:template match="indexterm[@class='startofrange']">
346   <xsl:choose>
347     <xsl:when test="$xep.extensions != 0">
348       <rx:begin-index-range>
349         <xsl:call-template name="anchor"/>
350         <xsl:attribute name="rx:key">
351           <xsl:value-of select="&primary;"/>
352           <xsl:if test="@significance='preferred'"><xsl:value-of select="$significant.flag"/></xsl:if>
353           <xsl:if test="secondary">
354             <xsl:text>, </xsl:text>
355             <xsl:value-of select="&secondary;"/>
356           </xsl:if>
357           <xsl:if test="tertiary">
358             <xsl:text>, </xsl:text>
359             <xsl:value-of select="&tertiary;"/>
360           </xsl:if>
361         </xsl:attribute>
362       </rx:begin-index-range>
363     </xsl:when>
364     <xsl:otherwise>
365       <xsl:call-template name="indexterm"/>
366     </xsl:otherwise>
367   </xsl:choose>
368 </xsl:template>
369
370 <xsl:template match="indexterm[@class='endofrange']">
371   <xsl:choose>
372     <xsl:when test="$xep.extensions != 0">
373       <rx:end-index-range>
374         <xsl:attribute name="ref-id">
375           <xsl:value-of select="@startref"/>
376         </xsl:attribute>
377       </rx:end-index-range>
378     </xsl:when>
379     <xsl:otherwise>
380       <xsl:call-template name="indexterm"/>
381     </xsl:otherwise>
382   </xsl:choose>
383 </xsl:template>
384
385 <!-- ==================================================================== -->
386
387 <xsl:template match="indexentry">
388   <fo:block>
389     <!-- don't process 'seeie's from here -->
390     <xsl:apply-templates select="primaryie|secondaryie|tertiaryie|seealsoie"/>
391   </fo:block>
392 </xsl:template>
393
394 <xsl:template match="primaryie">
395   <fo:block>
396     <xsl:apply-templates/>
397     <xsl:if test="following-sibling::seeie">
398       <xsl:text> (</xsl:text>
399       <xsl:call-template name="gentext">
400         <xsl:with-param name="key" select="'see'"/>
401       </xsl:call-template>
402       <xsl:text> </xsl:text>
403       <xsl:apply-templates select="following-sibling::seeie"/>
404       <xsl:text>)</xsl:text>
405     </xsl:if>
406   </fo:block>
407 </xsl:template>
408
409 <xsl:template match="secondaryie">
410   <fo:block start-indent="1pc">
411     <xsl:apply-templates/>
412     <xsl:if test="following-sibling::seeie">
413       <xsl:text> (</xsl:text>
414       <xsl:call-template name="gentext">
415         <xsl:with-param name="key" select="'see'"/>
416       </xsl:call-template>
417       <xsl:text> </xsl:text>
418       <xsl:apply-templates select="following-sibling::seeie"/>
419       <xsl:text>)</xsl:text>
420     </xsl:if>
421   </fo:block>
422 </xsl:template>
423
424 <xsl:template match="tertiaryie">
425   <fo:block start-indent="2pc">
426     <xsl:apply-templates/>
427     <xsl:if test="following-sibling::seeie">
428       <xsl:text> (</xsl:text>
429       <xsl:call-template name="gentext">
430         <xsl:with-param name="key" select="'see'"/>
431       </xsl:call-template>
432       <xsl:text> </xsl:text>
433       <xsl:apply-templates select="following-sibling::seeie"/>
434       <xsl:text>)</xsl:text>
435     </xsl:if>
436   </fo:block>
437 </xsl:template>
438
439 <xsl:template match="seeie">
440   <fo:inline>
441     <xsl:apply-templates/>
442   </fo:inline>
443 </xsl:template>
444
445 <xsl:template match="seealsoie">
446   <fo:block>
447     <xsl:attribute name="start-indent">
448       <xsl:choose>
449         <xsl:when test="(preceding-sibling::tertiaryie |
450                          preceding-sibling::secondaryie)[last()]
451                          [self::tertiaryie]">3pc</xsl:when>
452         <xsl:when test="(preceding-sibling::tertiaryie |
453                          preceding-sibling::secondaryie)[last()]
454                          [self::secondaryie]">2pc</xsl:when>
455         <xsl:otherwise>1pc</xsl:otherwise>
456       </xsl:choose>
457     </xsl:attribute>
458     <xsl:text>(</xsl:text>
459     <xsl:call-template name="gentext">
460       <xsl:with-param name="key" select="'seealso'"/>
461     </xsl:call-template>
462     <xsl:text> </xsl:text>
463     <xsl:apply-templates/>
464     <xsl:text>)</xsl:text>
465   </fo:block>
466 </xsl:template>
467
468 <!-- Determines if an object should be inserted as an fo:inline
469      or an fo:block.  Used for indexterms -->
470 <xsl:template name="inline.or.block">
471   <xsl:param name="parentnode" select=".."/>
472
473   <xsl:variable name="parent" select="concat('|', local-name($parentnode), '|')"/>
474
475   <xsl:variable name="block.parents" select="'|answer|appendix|appendixinfo|article|articleinfo|bibliodiv|bibliography|bibliographyinfo|blockinfo|blockquote|bookinfo|callout|caution|chapter|chapterinfo|dedication|example|figure|formalpara|funcsynopsisinfo|glossary|glossaryinfo|glossdef|glossdiv|glossentry|highlights|important|index|indexinfo|info|informalexample|informalfigure|informaltable|itemizedlist|legalnotice|listitem|msgexplan|msgtext|note|objectinfo|orderedlist|partinfo|partintro|preface|prefaceinfo|procedure|qandadiv|qandaset|question|refentry|refentryinfo|referenceinfo|refmeta|refmiscinfo|refsect1|refsect1info|refsect2|refsect2info|refsect3|refsect3info|refsection|refsectioninfo|refsynopsisdiv|refsynopsisdivinfo|revdescription|screeninfo|sect1|sect1info|sect2|sect2info|sect3|sect3info|sect4|sect4info|sect5|sect5info|section|sectioninfo|setindex|setindexinfo|setinfo|sidebar|sidebarinfo|simplesect|step|table|task|taskprerequisites|taskrelated|tasksummary|tip|variablelist|warning|'"/>
476
477   <xsl:choose>
478     <xsl:when test="contains($block.parents, $parent)">fo:block</xsl:when>
479     <xsl:when test="$fop1.extensions != 0">fo:wrapper</xsl:when>
480     <xsl:otherwise>fo:inline</xsl:otherwise>
481   </xsl:choose>
482 </xsl:template>
483
484 </xsl:stylesheet>