2
<!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
3
<!--#############################################################################
4
| $Id: index.mod.xsl,v 1.21 2004/08/12 05:47:32 j-devenish Exp $
5
|- #############################################################################
6
| $Author: j-devenish $
7
+ ############################################################################## -->
9
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
11
exclude-result-prefixes="doc" version='1.0'>
13
<doc:reference id="index" xmlns="">
15
<releaseinfo role="meta">
16
$Id: index.mod.xsl,v 1.21 2004/08/12 05:47:32 j-devenish Exp $
23
<year>2000</year><year>2001</year><year>2002</year><year>2003</year>
24
<holder>Ramon Casellas</holder>
27
<doc:revision rcasver="1.11">&rev_2003_05;</doc:revision>
30
<title>Indices <filename>index.mod.xsl</filename></title>
32
<para>The file <filename>index.mod.xsl</filename> contains the
33
XSL template for <doc:db>index</doc:db>.</para>
35
<para>Describe indexterm-range key.</para>
38
An <literal>indexterm-range</literal> XSLT key is defined for
39
all <quote>startofrange</quote> <doc:db>indexterm</doc:db>
40
elements, matching their <sgmltag
41
class="attribute">id</sgmltag> attribute.
47
<!-- Our key for ranges -->
48
<xsl:key name="indexterm-range" match="indexterm[@class='startofrange']" use="@id"/>
50
<doc:template basename="index" xmlns="">
51
<refpurpose>Process <doc:db>index</doc:db> and <doc:db>setindex</doc:db> elements</refpurpose>
54
Produce a chapter-level index (for <doc:db
55
basename="book">books</doc:db>, or section-level for <doc:db
56
basename='article'>articles</doc:db>) in &LaTeX;.
66
You will need to run your typesetter at least twice, and
67
possibly three times, to have the index generated normally (you
68
will also need to run the <command>makeidx</command> command).
75
<simplelist type='inline'>
82
<xsl:template match="index|setindex">
83
<xsl:variable name="preamble" select="node()[not(self::indexinfo or self::setindexinfo or self::title or self::subtitle or self::titleabbrev or self::indexdiv or self::indexentry)]"/>
84
<xsl:text>\setlength\saveparskip\parskip </xsl:text>
85
<xsl:text>\setlength\saveparindent\parindent </xsl:text>
86
<xsl:text>\begin{dbtolatexindex}{</xsl:text>
87
<xsl:call-template name="generate.label.id"/>
88
<xsl:text>}{</xsl:text>
89
<xsl:call-template name="extract.object.title">
90
<xsl:with-param name="object" select="."/>
91
<!-- perhaps we *should* define \indexname according to
92
gentext.element.name, but instead we let LaTeX/Babel handle it. -->
94
<xsl:text>} </xsl:text>
95
<xsl:text>\setlength\tempparskip\parskip \setlength\tempparindent\parindent </xsl:text>
96
<xsl:text>\parskip\saveparskip \parindent\saveparindent </xsl:text>
97
<xsl:text>\noindent </xsl:text><!-- -->
98
<xsl:apply-templates select="$preamble"/>
99
<xsl:call-template name="map.begin"/>
100
<xsl:text>\parskip\tempparskip </xsl:text>
101
<xsl:text>\parindent\tempparindent </xsl:text>
102
<xsl:text>\makeatletter\@input@{\jobname.ind}\makeatother </xsl:text>
103
<xsl:call-template name="map.end"/>
104
<xsl:text>\end{dbtolatexindex} </xsl:text>
107
<doc:template xmlns="">
108
<refpurpose> Essential preamble for <filename>index.mod.xsl</filename> support </refpurpose>
112
This preamble aids the following:
116
Allow user to override the &LaTeX; default index name
117
with a &DocBook; localisation.
120
Integrate <doc:db>index</doc:db>/@<sgmltag
121
class="attribute">id</sgmltag> cross-references
122
with &LaTeX; and tables of contents (makes indices
123
behave a bit like chapters).
126
Allow <quote>preamble</quote> templates or
127
mappings to be applied for indices.
136
<listitem><simpara>&preamble;</simpara></listitem>
140
<xsl:template name="latex.preamble.essential.index">
144
% index labeling helper
145
\newif\ifdocbooktolatexprintindex\docbooktolatexprintindextrue
146
\let\dbtolatex@@theindex\theindex
147
\let\dbtolatex@@endtheindex\endtheindex
148
\@ifundefined{@openrighttrue}{\newif\if@openright}{}
149
\def\theindex{\relax}
150
\def\endtheindex{\relax}
151
\newenvironment{dbtolatexindex}[2]
153
\if@openright\cleardoublepage\else\clearpage\fi
154
\let\dbtolatex@@indexname\indexname
155
\def\dbtolatex@current@indexname{#2}
156
\ifx\dbtolatex@current@indexname\@empty \def\dbtolatex@current@indexname{\dbtolatex@@indexname}
158
\def\dbtolatex@indexlabel{%
159
\ifnum \c@secnumdepth >\m@ne \ifx\c@chapter\undefined\refstepcounter{section}\else\refstepcounter{chapter}\fi\fi%
160
\label{#1}\hypertarget{#1}{\dbtolatex@current@indexname}%
161
\global\docbooktolatexprintindexfalse}
162
\def\indexname{\ifdocbooktolatexprintindex\dbtolatex@indexlabel\else\dbtolatex@current@indexname\fi}
166
\dbtolatex@@endtheindex\let\indexname\dbtolatex@@indexname
169
\newlength\saveparskip \newlength\saveparindent
170
\newlength\tempparskip \newlength\tempparindent
176
<xsl:template match="index/title">
177
<xsl:call-template name="label.id"> <xsl:with-param name="object" select=".."/> </xsl:call-template>
180
<xsl:template match="indexdiv">
181
<xsl:apply-templates/>
184
<xsl:template match="indexdiv/title">
185
<xsl:call-template name="label.id"> <xsl:with-param name="object" select=".."/> </xsl:call-template>
188
<xsl:template match="primary|secondary|tertiary|see|seealso"/>
192
<doc:template xmlns="">
193
<refpurpose>Process <doc:db>indexterm</doc:db> elements</refpurpose>
196
Identify an instance of an indexed term.
201
<listitem><simpara><xref linkend="param.latex.generate.indexterm"/></simpara></listitem>
209
&LaTeX; code used to format the displayed entry.
210
By default, this is drawn from any <quote>latex-index-style</quote>
211
processing instructions (and is therefore empty most of the time).
212
</simpara></listitem>
218
A &LaTeX; <function condition="latex">index</function> command
219
is issued. When an <doc:db>index</doc:db> element is included
220
in your document and indexing is enabled, this indexterm will
224
When <link linkend="param.latex.is.draft">draft mode</link> is
225
enabled, the physical location of <doc:db
226
basename="indexterm">indexterms</doc:db> will be highlighted
227
within the body of the text as well as appearing in the index
231
&DB2LaTeX; includes some logic to handle the
232
<quote>startofrange</quote> and <quote>endofrange</quote>
236
It is possible to format an entry (e.g.
237
make it bold or italic) by inserting a processing instruction
238
named <quote>latex-index-style</quote> in the appropriate
243
<simplelist type='inline'>
253
<listitem><simpara><xref linkend="param.latex.is.draft"/></simpara></listitem>
257
<!-- INDEX TERM CONTENT MODEL
266
<xsl:template match="indexterm">
267
<xsl:if test="$latex.generate.indexterm='1'">
268
<xsl:variable name="idxterm">
269
<xsl:apply-templates mode="indexterm"/>
272
<xsl:if test="@class and @zone">
273
<xsl:message terminate="yes">Error: Only one attribute (@class or @zone) is in indexterm possible!</xsl:message>
276
<xsl:if test="not(preceding-sibling::para) and following-sibling::para">
277
<xsl:text> </xsl:text>
281
<xsl:when test="@class='startofrange'">
282
<xsl:text>\index{</xsl:text>
283
<xsl:value-of select="$idxterm"/>
284
<xsl:text>|(}</xsl:text>
286
<xsl:when test="@class='endofrange'">
288
<xsl:when test="count(key('indexterm-range',@startref)) = 0">
289
<xsl:message terminate="yes"><xsl:text>Error: No indexterm with </xsl:text>
290
<xsl:text>id='</xsl:text><xsl:value-of select="@startref"/>
291
<xsl:text>' found!</xsl:text>
292
<xsl:text> Check your attributs id/startref in your indexterms!</xsl:text>
296
<xsl:variable name="thekey" select="key('indexterm-range',@startref)"/>
297
<xsl:for-each select="$thekey[1]">
298
<xsl:text>\index{</xsl:text>
299
<xsl:apply-templates mode="indexterm"/>
300
<xsl:text>|)}</xsl:text>
306
<xsl:text>\index{</xsl:text>
307
<xsl:value-of select="$idxterm"/>
308
<xsl:text>}</xsl:text>
311
<xsl:if test="not(preceding-sibling::para) and following-sibling::para">
312
<xsl:text>%</xsl:text><!-- gobble following para's initial newline -->
314
<xsl:if test="preceding-sibling::para">
315
<xsl:text> </xsl:text>
320
<xsl:template match="*" mode="indexterm">
321
<xsl:message>WARNING: Element '<xsl:value-of select="local-name()"/>' in indexterm not supported and skipped!</xsl:message>
325
<xsl:template match="acronym|foreignphrase" mode="indexterm">
326
<xsl:apply-templates mode="indexterm"/>
330
<doc:template xmlns="">
331
<refpurpose>Process the contents of <doc:db basename="indexterm">indexterms</doc:db></refpurpose>
334
Register a primary index term.
342
Calls <xref linkend="template.index.subterm"/>.
346
<xsl:template match="primary" mode="indexterm">
347
<xsl:call-template name="index.subterm"/>
350
<doc:template xmlns="">
351
<refpurpose>Process the contents of <doc:db basename="indexterm">indexterms</doc:db></refpurpose>
354
Register a secondary or tertiary index term.
362
Calls <xref linkend="template.index.subterm"/>.
366
<xsl:template match="secondary|tertiary" mode="indexterm">
367
<xsl:text>!</xsl:text>
368
<xsl:call-template name="index.subterm"/>
371
<doc:template xmlns="">
372
<refpurpose>Process the contents of <doc:db basename="indexterm">indexterms</doc:db></refpurpose>
375
Register a primary, secondary or tertiary index term.
384
If no <sgmltag class="attribute">sortas</sgmltag> attribute is
385
present, the contents of <doc:db>primary</doc:db>,
386
<doc:db>secondary</doc:db> and <doc:db>tertiary</doc:db>
387
elements are converted to text-only and no templates are
388
applied. If the <sgmltag class="attribute">sortas</sgmltag>
389
attribute is present and non-empty, its value is used for indexing
390
and sorting (but not for display)<!-- and templates
391
<emphasis>are</emphasis> applied for display purposes-->.
396
If a <quote>latex-index-style</quote> processing instruction is
397
present, the displayed indexterm will be formatted by treating
398
the content of the PI as a &LaTeX; command.
403
<xsl:template name="index.subterm">
404
<xsl:variable name="style" select="processing-instruction('latex-index-style')"/>
406
<xsl:when test="@sortas!=''">
407
<xsl:variable name="string">
408
<xsl:call-template name="scape-indexterm">
409
<xsl:with-param name="string" select="@sortas"/>
412
<xsl:variable name="content">
413
<xsl:call-template name="scape-indexterm">
414
<xsl:with-param name="string" select="."/>
417
<xsl:value-of select="normalize-space($string)"/>
418
<xsl:text>@{</xsl:text>
419
<xsl:value-of select="$style"/>
420
<xsl:text>{</xsl:text>
421
<xsl:value-of select="normalize-space($content)"/>
422
<xsl:text>}}</xsl:text>
425
<xsl:variable name="string">
426
<xsl:call-template name="scape-indexterm">
427
<xsl:with-param name="string" select="."/>
430
<xsl:value-of select="normalize-space($string)"/>
431
<xsl:if test="$style!=''">
432
<xsl:text>@{</xsl:text>
433
<xsl:value-of select="$style"/>
434
<xsl:text>{</xsl:text>
435
<xsl:value-of select="normalize-space($string)"/>
436
<xsl:text>}}</xsl:text>
441
<xsl:apply-templates mode="indexterm"/>
445
<doc:template xmlns="">
446
<refpurpose>Process the contents of <doc:db>see</doc:db> and <doc:db>seealso</doc:db> elements</refpurpose>
449
Annotate an index entry with a <quote>See</quote> or <quote>See also</quote> cross-reference.
457
Templates are applied.
458
<quote>See</quote> or <quote>see also</quote> text
459
is generated by <literal>gentext.element.name</literal>
460
and formatted in italics.
464
<xsl:template match="see|seealso" mode="indexterm">
465
<xsl:text>|textit{</xsl:text>
466
<xsl:call-template name="gentext.element.name"/>
467
<xsl:text>} {</xsl:text>
468
<xsl:apply-templates/>
470
<xsl:apply-templates mode="indexterm"/>
472
<xsl:text>} </xsl:text>
475
<doc:template xmlns="">
476
<refpurpose> Skip <doc:db>indexentry</doc:db>-related elements </refpurpose>
479
Ignores the elements.
487
&DB2LaTeX; only supports indices that are generated by &LaTeX; itself.
491
<xsl:template match="indexentry|primaryie|secondaryie|tertiaryie|seeie|seealsoie"/>