Moving docs tree to docs-xml to make room for generated docs in the release tarball.
[gd/samba-autobuild/.git] / docs-xml / xslt / db2latex-xsl / xsl / index.mod.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
3 <!--############################################################################# 
4 |       $Id: index.mod.xsl,v 1.17 2004/01/27 05:59:51 j-devenish Exp $
5 |- #############################################################################
6 |       $Author: j-devenish $
7 + ############################################################################## -->
8 <xsl:stylesheet
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'>
12
13         <doc:reference id="index" xmlns="">
14                 <referenceinfo>
15                         <releaseinfo role="meta">
16                                 $Id: index.mod.xsl,v 1.17 2004/01/27 05:59:51 j-devenish Exp $
17                         </releaseinfo>
18                         <authorgroup>
19                                 &ramon;
20                                 &james;
21                         </authorgroup>
22                         <copyright>
23                                 <year>2000</year><year>2001</year><year>2002</year><year>2003</year>
24                                 <holder>Ramon Casellas</holder>
25                         </copyright>
26                         <revhistory>
27                                 <doc:revision rcasver="1.11">&rev_2003_05;</doc:revision>
28                         </revhistory>
29                 </referenceinfo>
30                 <title>Indices <filename>index.mod.xsl</filename></title>
31                 <partintro>
32                         <para>The file <filename>index.mod.xsl</filename> contains the
33                         XSL template for <doc:db>index</doc:db>.</para>
34                         <!-- TODO: -->
35                         <para>Describe indexterm-range key.</para>
36                         <para>
37                                 
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.
42                                 
43                         </para>
44                 </partintro>
45         </doc:reference>
46
47         <!-- Our key for ranges -->
48         <xsl:key name="indexterm-range" match="indexterm[@class='startofrange']" use="@id"/>
49
50         <doc:template basename="index" xmlns="">
51                 <refpurpose>Process <doc:db>index</doc:db> and <doc:db>setindex</doc:db> elements</refpurpose>
52                 <doc:description>
53                         <para>
54                                 Produce a chapter-level index in &LaTeX;.
55                         </para>
56                 </doc:description>
57                 <doc:variables>
58                         &no_var;
59                 </doc:variables>
60                 <doc:notes>
61
62                         <para>
63
64                                 You will need to run your typesetter at least twice, and
65                                 possibly three times, to have the index generated normally (you
66                                 will also need to run the <command>makeidx</command> command).
67
68                         </para>
69
70                         &essential_preamble;
71                 </doc:notes>
72                 <doc:samples>
73                         <simplelist type='inline'>
74                                 &test_book;
75                                 &test_index;
76                                 &test_draft;
77                         </simplelist>
78                 </doc:samples>
79         </doc:template>
80         <xsl:template match="index|setindex">
81                 <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)]"/>
82       <xsl:text>\setlength\saveparskip\parskip&#10;</xsl:text>
83       <xsl:text>\setlength\saveparindent\parindent&#10;</xsl:text>
84                 <xsl:text>\begin{dbtolatexindex}{</xsl:text>
85                 <xsl:call-template name="generate.label.id"/>
86                 <xsl:text>}&#10;</xsl:text>
87       <xsl:text>\setlength\tempparskip\parskip \setlength\tempparindent\parindent&#10;</xsl:text>
88       <xsl:text>\parskip\saveparskip \parindent\saveparindent&#10;</xsl:text>
89       <xsl:text>\noindent </xsl:text><!-- &#10; -->
90                 <xsl:apply-templates select="$preamble"/>
91                 <xsl:call-template name="map.begin"/>
92       <xsl:text>\parskip\tempparskip&#10;</xsl:text>
93       <xsl:text>\parindent\tempparindent&#10;</xsl:text>
94                 <xsl:text>\makeatletter\@input@{\jobname.ind}\makeatother&#10;</xsl:text>
95                 <xsl:call-template name="map.end"/>
96                 <xsl:text>\end{dbtolatexindex}&#10;</xsl:text>
97         </xsl:template>
98
99         <doc:template xmlns="">
100                 <refpurpose> Essential preamble for <filename>index.mod.xsl</filename> support </refpurpose>
101                 <doc:description>
102                         <para>
103
104                                 This preamble aids the following:
105                                 <itemizedlist>
106                                         <listitem>
107                                                 <simpara>
108                                                         Allow user to override the &LaTeX; default index name
109                                                         with a &DocBook; localisation.
110                                                 </simpara>
111                                                 <simpara>
112                                                         Integrate <doc:db>index</doc:db>/@<sgmltag
113                                                         class="attribute">id</sgmltag> cross-references
114                                                         with &LaTeX; and tables of contents (makes indices
115                                                         behave a bit like chapters).
116                                                 </simpara>
117                                                 <simpara>
118                                                         Allow <quote>preamble</quote> templates or
119                                                         mappings to be applied for indices.
120                                                 </simpara>
121                                         </listitem>
122                                 </itemizedlist>
123
124                         </para>
125                 </doc:description>
126                 <doc:seealso>
127                         <itemizedlist>
128                                 <listitem><simpara>&preamble;</simpara></listitem>
129                         </itemizedlist>
130                 </doc:seealso>
131         </doc:template>
132         <xsl:template name="latex.preamble.essential.index">
133                 <xsl:text>
134                         <![CDATA[
135 % index labeling helper
136 \newif\ifdocbooktolatexprintindex\docbooktolatexprintindextrue
137 \let\dbtolatex@@theindex\theindex
138 \let\dbtolatex@@endtheindex\endtheindex
139 \def\theindex{\relax}
140 \def\endtheindex{\relax}
141 \newenvironment{dbtolatexindex}[1]
142    {
143 \if@openright\cleardoublepage\else\clearpage\fi
144 \let\dbtolatex@@indexname\indexname
145 \def\dbtolatex@indexlabel{%
146  \ifnum \c@secnumdepth >\m@ne \refstepcounter{chapter}\fi%
147  \label{#1}\hypertarget{#1}{\dbtolatex@@indexname}%
148  \global\docbooktolatexprintindexfalse}
149 \def\indexname{\ifdocbooktolatexprintindex\dbtolatex@indexlabel\else\dbtolatex@@indexname\fi}
150 \dbtolatex@@theindex
151    }
152    {
153 \dbtolatex@@endtheindex\let\indexname\dbtolatex@@indexname
154    }
155
156 \newlength\saveparskip \newlength\saveparindent
157 \newlength\tempparskip \newlength\tempparindent
158 ]]>
159                 </xsl:text>
160         </xsl:template>
161
162 <!--
163         <xsl:template match="index/title">
164                 <xsl:call-template name="label.id"> <xsl:with-param name="object" select=".."/> </xsl:call-template>
165         </xsl:template>
166
167 <xsl:template match="indexdiv">
168         <xsl:apply-templates/>
169 </xsl:template>
170
171 <xsl:template match="indexdiv/title">
172         <xsl:call-template name="label.id"> <xsl:with-param name="object" select=".."/> </xsl:call-template>
173 </xsl:template>
174
175         <xsl:template match="primary|secondary|tertiary|see|seealso"/>
176
177 -->
178
179         <doc:template xmlns="">
180                 <refpurpose>Process <doc:db>indexterm</doc:db> elements</refpurpose>
181                 <doc:description>
182                         <para>
183                                 Identify an instance of an indexed term.
184                         </para>
185                 </doc:description>
186                 <doc:variables>
187                         <itemizedlist>
188                                 <listitem><simpara><xref linkend="param.latex.generate.indexterm"/></simpara></listitem>
189                         </itemizedlist>
190                 </doc:variables>
191                 <doc:params>
192                         <variablelist>
193                                 <varlistentry>
194                                         <term>style</term>
195                                         <listitem><simpara>
196                                                 &LaTeX; code used to format the displayed entry.
197                                                 By default, this is drawn from any <quote>latex-index-style</quote>
198                                                 processing instructions (and is therefore empty most of the time).
199                                         </simpara></listitem>
200                                 </varlistentry>
201                         </variablelist>
202                 </doc:params>
203                 <doc:notes>
204                         <para>
205                                 A &LaTeX; <function condition="latex">index</function> command
206                                 is issued. When an <doc:db>index</doc:db> element is included
207                                 in your document and indexing is enabled, this indexterm will
208                                 be indexed.
209                         </para>
210                         <para>
211                                 When <link linkend="param.latex.is.draft">draft mode</link> is
212                                 enabled, the physical location of <doc:db
213                                 basename="indexterm">indexterms</doc:db> will be highlighted
214                                 within the body of the text as well as appearing in the index
215                                 proper.
216                         </para>
217                         <para>
218                                 &DB2LaTeX; includes some logic to handle the
219                                 <quote>startofrange</quote> and <quote>endofrange</quote>
220                                 classes.
221                         </para>
222                         <para>
223                                 It is possible to format an entry (e.g.
224                                 make it bold or italic) by inserting a processing instruction
225                                 named <quote>latex-index-style</quote> in the appropriate
226                                 subterm.
227                         </para>
228                 </doc:notes>
229                 <doc:samples>
230                         <simplelist type='inline'>
231                                 &test_book;
232                                 &test_ddh;
233                                 &test_draft1;
234                                 &test_draft2;
235                                 &test_index;
236                         </simplelist>
237                 </doc:samples>
238                 <doc:seealso>
239                         <itemizedlist>
240                                 <listitem><simpara><xref linkend="param.latex.is.draft"/></simpara></listitem>
241                         </itemizedlist>
242                 </doc:seealso>
243         </doc:template>
244         <!-- INDEX TERM CONTENT MODEL
245         IndexTerm ::=
246         (Primary,
247         ((Secondary,
248         ((Tertiary,
249         (See|SeeAlso+)?)|
250         See|SeeAlso+)?)|
251         See|SeeAlso+)?)
252         -->
253         <xsl:template match="indexterm">
254                 <xsl:if test="$latex.generate.indexterm='1'">
255                         <xsl:variable name="idxterm">
256                                 <xsl:apply-templates mode="indexterm"/>
257                         </xsl:variable>
258
259                         <xsl:if test="@class and @zone">
260                                 <xsl:message terminate="yes">Error: Only one attribute (@class or @zone) is in indexterm possible!</xsl:message>
261                         </xsl:if>
262
263                         <xsl:choose>
264                                 <xsl:when test="@class='startofrange'">
265                                         <xsl:text>\index{</xsl:text>
266                                         <xsl:value-of select="$idxterm"/>
267                                         <xsl:text>|(}</xsl:text>
268                                 </xsl:when>
269                                 <xsl:when test="@class='endofrange'">
270                                         <xsl:choose>
271                                                 <xsl:when test="count(key('indexterm-range',@startref)) = 0">
272                                                         <xsl:message terminate="yes"><xsl:text>Error: No indexterm with </xsl:text>
273                                                         <xsl:text>id='</xsl:text><xsl:value-of select="@startref"/>
274                                                         <xsl:text>' found!</xsl:text>
275                                                         <xsl:text>  Check your attributs id/startref in your indexterms!</xsl:text>
276                                                         </xsl:message>
277                                                 </xsl:when>
278                                                 <xsl:otherwise>
279                                                         <xsl:variable name="thekey" select="key('indexterm-range',@startref)"/>
280                                                         <xsl:for-each select="$thekey[1]">
281                                                                 <xsl:text>\index{</xsl:text>
282                                                                 <xsl:apply-templates mode="indexterm"/>
283                                                                 <xsl:text>|)}</xsl:text>
284                                                         </xsl:for-each>
285                                                 </xsl:otherwise>
286                                         </xsl:choose>
287                                 </xsl:when>
288                                 <xsl:otherwise>
289                                         <xsl:text>\index{</xsl:text>
290                                         <xsl:value-of select="$idxterm"/>
291                                         <xsl:text>}</xsl:text>
292                                 </xsl:otherwise>
293                         </xsl:choose>
294                 </xsl:if>
295         </xsl:template>
296
297         <xsl:template match="*" mode="indexterm">
298                 <xsl:message>WARNING: Element '<xsl:value-of select="local-name()"/>' in indexterm not supported and skipped!</xsl:message>
299         </xsl:template>
300
301         <!--
302         <xsl:template match="acronym|foreignphrase" mode="indexterm">
303                 <xsl:apply-templates mode="indexterm"/>
304         </xsl:template>
305         -->
306
307         <doc:template xmlns="">
308                 <refpurpose>Process the contents of <doc:db basename="indexterm">indexterms</doc:db></refpurpose>
309                 <doc:description>
310                         <para>
311                                 Register a primary index term.
312                         </para>
313                 </doc:description>
314                 <doc:variables>
315                         &no_var;
316                 </doc:variables>
317                 <doc:notes>
318                         <para>
319                                 Calls <xref linkend="template.index.subterm"/>.
320                         </para>
321                 </doc:notes>
322         </doc:template>
323         <xsl:template match="primary" mode="indexterm">
324                 <xsl:call-template name="index.subterm"/>
325         </xsl:template>
326
327         <doc:template xmlns="">
328                 <refpurpose>Process the contents of <doc:db basename="indexterm">indexterms</doc:db></refpurpose>
329                 <doc:description>
330                         <para>
331                                 Register a secondary or tertiary index term.
332                         </para>
333                 </doc:description>
334                 <doc:variables>
335                         &no_var;
336                 </doc:variables>
337                 <doc:notes>
338                         <para>
339                                 Calls <xref linkend="template.index.subterm"/>.
340                         </para>
341                 </doc:notes>
342         </doc:template>
343         <xsl:template match="secondary|tertiary" mode="indexterm">
344                 <xsl:text>!</xsl:text>
345                 <xsl:call-template name="index.subterm"/>
346         </xsl:template>
347
348         <doc:template xmlns="">
349                 <refpurpose>Process the contents of <doc:db basename="indexterm">indexterms</doc:db></refpurpose>
350                 <doc:description>
351                         <para>
352                                 Register a primary, secondary or tertiary index term.
353                         </para>
354                 </doc:description>
355                 <doc:variables>
356                         &no_var;
357                 </doc:variables>
358                 <doc:notes>
359                         <para>
360
361                                 If no <sgmltag class="attribute">sortas</sgmltag> attribute is
362                                 present, the contents of <doc:db>primary</doc:db>,
363                                 <doc:db>secondary</doc:db> and <doc:db>tertiary</doc:db>
364                                 elements are converted to text-only and no templates are
365                                 applied. If the <sgmltag class="attribute">sortas</sgmltag>
366                                 attribute is present and non-empty, its value is used for indexing
367                                 and sorting (but not for display)<!-- and templates
368                                 <emphasis>are</emphasis> applied for display purposes-->.
369
370                         </para>
371                         <para>
372
373                                 If a <quote>latex-index-style</quote> processing instruction is
374                                 present, the displayed indexterm will be formatted by treating
375                                 the content of the PI as a &LaTeX; command.
376
377                         </para>
378                 </doc:notes>
379         </doc:template>
380         <xsl:template name="index.subterm">
381                 <xsl:variable name="style" select="processing-instruction('latex-index-style')"/>
382                 <xsl:choose>
383                         <xsl:when test="@sortas!=''">
384                                 <xsl:variable name="string">
385                                         <xsl:call-template name="scape-indexterm">
386                                                 <xsl:with-param name="string" select="@sortas"/>
387                                         </xsl:call-template>
388                                 </xsl:variable>
389                                 <xsl:variable name="content">
390                                         <xsl:call-template name="scape-indexterm">
391                                                 <xsl:with-param name="string" select="."/>
392                                         </xsl:call-template>
393                                 </xsl:variable>
394                                 <xsl:value-of select="normalize-space($string)"/>
395                                 <xsl:text>@{</xsl:text>
396                                 <xsl:value-of select="$style"/>
397                                 <xsl:text>{</xsl:text>
398                                 <xsl:value-of select="normalize-space($content)"/>
399                                 <xsl:text>}}</xsl:text>
400                         </xsl:when>
401                         <xsl:otherwise>
402                                 <xsl:variable name="string">
403                                         <xsl:call-template name="scape-indexterm">
404                                                 <xsl:with-param name="string" select="."/>
405                                         </xsl:call-template>
406                                 </xsl:variable>
407                                 <xsl:value-of select="normalize-space($string)"/>
408                                 <xsl:if test="$style!=''">
409                                         <xsl:text>@{</xsl:text>
410                                         <xsl:value-of select="$style"/>
411                                         <xsl:text>{</xsl:text>
412                                         <xsl:value-of select="normalize-space($string)"/>
413                                         <xsl:text>}}</xsl:text>
414                                 </xsl:if>
415                         </xsl:otherwise>
416                 </xsl:choose>
417                 <!--
418                 <xsl:apply-templates mode="indexterm"/>
419                 -->
420         </xsl:template>
421
422         <doc:template xmlns="">
423                 <refpurpose>Process the contents of <doc:db>see</doc:db> and <doc:db>seealso</doc:db> elements</refpurpose>
424                 <doc:description>
425                         <para>
426                                 Annotate an index entry with a <quote>See</quote> or <quote>See also</quote> cross-reference.
427                         </para>
428                 </doc:description>
429                 <doc:variables>
430                         &no_var;
431                 </doc:variables>
432                 <doc:notes>
433                         <para>
434                                 Templates are applied.
435                                 <quote>See</quote> or <quote>see also</quote> text
436                                 is generated by <literal>gentext.element.name</literal>
437                                 and formatted in italics.
438                         </para>
439                 </doc:notes>
440         </doc:template>
441         <xsl:template match="see|seealso" mode="indexterm">
442                 <xsl:text>|textit{</xsl:text>
443                 <xsl:call-template name="gentext.element.name"/>
444                 <xsl:text>} {</xsl:text>
445                 <xsl:apply-templates/>
446                 <!--
447                 <xsl:apply-templates mode="indexterm"/>
448                 -->
449                 <xsl:text>} </xsl:text>
450         </xsl:template>
451
452         <doc:template xmlns="">
453                 <refpurpose> Skip <doc:db>indexentry</doc:db>-related elements </refpurpose>
454                 <doc:description>
455                         <para>
456                                 Ignores the elements.
457                         </para>
458                 </doc:description>
459                 <doc:variables>
460                         &no_var;
461                 </doc:variables>
462                 <doc:notes>
463                         <para>
464                                 &DB2LaTeX; only supports indices that are generated by &LaTeX; itself.
465                         </para>
466                 </doc:notes>
467         </doc:template>
468         <xsl:template match="indexentry|primaryie|secondaryie|tertiaryie|seeie|seealsoie"/>
469
470 </xsl:stylesheet>