Project

General

Profile

1 26607 alessia.ba
<?xml version='1.0'?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                version='1.0'>
4
5
<!-- ********************************************************************
6
     $Id: index.xsl 8421 2009-05-04 07:49:49Z bobstayton $
7
     ********************************************************************
8
9
     This file is part of the XSL DocBook Stylesheet distribution.
10
     See ../README or http://docbook.sf.net/release/xsl/current/ for
11
     copyright and other information.
12
13
     ******************************************************************** -->
14
15
<!-- ==================================================================== -->
16
17
<xsl:template match="index">
18
  <!-- some implementations use completely empty index tags to indicate -->
19
  <!-- where an automatically generated index should be inserted. so -->
20
  <!-- if the index is completely empty, skip it. Unless generate.index -->
21
  <!-- is non-zero, in which case, this is where the automatically -->
22
  <!-- generated index should go. -->
23
24
  <xsl:call-template name="id.warning"/>
25
26
  <xsl:if test="count(*)>0 or $generate.index != '0'">
27
    <div>
28
      <xsl:apply-templates select="." mode="common.html.attributes"/>
29
      <xsl:if test="$generate.id.attributes != 0">
30
        <xsl:attribute name="id">
31
          <xsl:call-template name="object.id"/>
32
        </xsl:attribute>
33
      </xsl:if>
34
35
      <xsl:call-template name="index.titlepage"/>
36
      <xsl:choose>
37
	<xsl:when test="indexdiv">
38
	  <xsl:apply-templates/>
39
	</xsl:when>
40
	<xsl:otherwise>
41
	  <xsl:apply-templates select="*[not(self::indexentry)]"/>
42
	  <!-- Because it's actually valid for Index to have neither any -->
43
	  <!-- Indexdivs nor any Indexentries, we need to check and make -->
44
	  <!-- sure that at least one Indexentry exists, and generate a -->
45
	  <!-- wrapper dl if there is at least one; otherwise, do nothing. -->
46
	  <xsl:if test="indexentry">
47
	    <!-- The indexentry template assumes a parent dl wrapper has -->
48
	    <!-- been generated; for Indexes that have Indexdivs, the dl -->
49
	    <!-- wrapper is generated by the indexdiv template; however, -->
50
	    <!-- for Indexes that lack Indexdivs, if we don't generate a -->
51
	    <!-- dl here, HTML output will not be valid. -->
52
	    <dl>
53
	      <xsl:apply-templates select="indexentry"/>
54
	    </dl>
55
	  </xsl:if>
56
	</xsl:otherwise>
57
      </xsl:choose>
58
59
      <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
60
        <xsl:call-template name="generate-index">
61
          <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
62
        </xsl:call-template>
63
      </xsl:if>
64
65
      <xsl:if test="not(parent::article)">
66
        <xsl:call-template name="process.footnotes"/>
67
      </xsl:if>
68
    </div>
69
  </xsl:if>
70
</xsl:template>
71
72
<xsl:template match="setindex">
73
  <!-- some implementations use completely empty index tags to indicate -->
74
  <!-- where an automatically generated index should be inserted. so -->
75
  <!-- if the index is completely empty, skip it. Unless generate.index -->
76
  <!-- is non-zero, in which case, this is where the automatically -->
77
  <!-- generated index should go. -->
78
79
  <xsl:call-template name="id.warning"/>
80
81
  <xsl:if test="count(*)>0 or $generate.index != '0'">
82
    <div>
83
      <xsl:apply-templates select="." mode="common.html.attributes"/>
84
      <xsl:if test="$generate.id.attributes != 0">
85
        <xsl:attribute name="id">
86
          <xsl:call-template name="object.id"/>
87
        </xsl:attribute>
88
      </xsl:if>
89
90
      <xsl:call-template name="setindex.titlepage"/>
91
      <xsl:apply-templates/>
92
93
      <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
94
        <xsl:call-template name="generate-index">
95
          <xsl:with-param name="scope" select="/"/>
96
        </xsl:call-template>
97
      </xsl:if>
98
99
      <xsl:if test="not(parent::article)">
100
        <xsl:call-template name="process.footnotes"/>
101
      </xsl:if>
102
    </div>
103
  </xsl:if>
104
</xsl:template>
105
106
<xsl:template match="index/indexinfo"></xsl:template>
107
<xsl:template match="index/info"></xsl:template>
108
<xsl:template match="index/title"></xsl:template>
109
<xsl:template match="index/subtitle"></xsl:template>
110
<xsl:template match="index/titleabbrev"></xsl:template>
111
112
<!-- ==================================================================== -->
113
114
<xsl:template match="indexdiv">
115
  <xsl:call-template name="id.warning"/>
116
117
  <div>
118
    <xsl:apply-templates select="." mode="common.html.attributes"/>
119
    <xsl:if test="$generate.id.attributes != 0">
120
      <xsl:attribute name="id">
121
        <xsl:call-template name="object.id"/>
122
      </xsl:attribute>
123
    </xsl:if>
124
125
    <xsl:call-template name="anchor"/>
126
    <xsl:apply-templates select="*[not(self::indexentry)]"/>
127
    <dl>
128
      <xsl:apply-templates select="indexentry"/>
129
    </dl>
130
  </div>
131
</xsl:template>
132
133
<xsl:template match="indexdiv/title">
134
  <h3>
135
    <xsl:apply-templates select="." mode="common.html.attributes"/>
136
    <xsl:apply-templates/>
137
  </h3>
138
</xsl:template>
139
140
<!-- ==================================================================== -->
141
142
<xsl:template match="indexterm">
143
  <!-- this one must have a name, even if it doesn't have an ID -->
144
  <xsl:variable name="id">
145
    <xsl:call-template name="object.id"/>
146
  </xsl:variable>
147
148
  <a class="indexterm" name="{$id}"/>
149
</xsl:template>
150
151
<xsl:template match="primary|secondary|tertiary|see|seealso">
152
</xsl:template>
153
154
<!-- ==================================================================== -->
155
156
<xsl:template match="indexentry">
157
  <xsl:apply-templates select="primaryie"/>
158
</xsl:template>
159
160
<xsl:template match="primaryie">
161
  <dt>
162
    <xsl:apply-templates/>
163
  </dt>
164
  <dd>
165
    <xsl:apply-templates select="following-sibling::seeie
166
                                   [not(preceding-sibling::secondaryie)]"
167
                         mode="indexentry"/>
168
    <xsl:apply-templates select="following-sibling::seealsoie
169
                                   [not(preceding-sibling::secondaryie)]"
170
                         mode="indexentry"/>
171
    <xsl:apply-templates select="following-sibling::secondaryie"
172
                         mode="indexentry"/>
173
  </dd>
174
</xsl:template>
175
176
<!-- Handled in mode to convert flat list to structured output -->
177
<xsl:template match="secondaryie">
178
</xsl:template>
179
<xsl:template match="tertiaryie">
180
</xsl:template>
181
<xsl:template match="seeie|seealsoie">
182
</xsl:template>
183
184
<xsl:template match="secondaryie" mode="indexentry">
185
  <dl>
186
    <dt>
187
      <xsl:apply-templates/>
188
    </dt>
189
    <dd>
190
      <!-- select following see* elements up to next secondaryie or tertiary or end -->
191
      <xsl:variable name="after.this"
192
              select="following-sibling::*"/>
193
      <xsl:variable name="next.entry"
194
              select="(following-sibling::secondaryie|following-sibling::tertiaryie)[1]"/>
195
      <xsl:variable name="before.entry"
196
                    select="$next.entry/preceding-sibling::*"/>
197
      <xsl:variable name="see.intersection"
198
             select="$after.this[count(.|$before.entry) = count($before.entry)]
199
                                [self::seeie or self::seealsoie]"/>
200
      <xsl:choose>
201
        <xsl:when test="count($see.intersection) != 0">
202
          <xsl:apply-templates select="$see.intersection" mode="indexentry"/>
203
        </xsl:when>
204
        <xsl:when test="count($next.entry) = 0">
205
          <xsl:apply-templates select="following-sibling::seeie"
206
                               mode="indexentry"/>
207
          <xsl:apply-templates select="following-sibling::seealsoie"
208
                               mode="indexentry"/>
209
        </xsl:when>
210
      </xsl:choose>
211
212
      <!-- now process any tertiaryie before the next secondaryie -->
213
      <xsl:variable name="before.next.secondary"
214
              select="following-sibling::secondaryie[1]/preceding-sibling::*"/>
215
      <xsl:variable name="tertiary.intersection"
216
             select="$after.this[count(.|$before.next.secondary) =
217
                                 count($before.next.secondary)]
218
                                [not(self::seeie) and not(self::seealsoie)]"/>
219
      <xsl:choose>
220
        <xsl:when test="count($tertiary.intersection) != 0">
221
          <xsl:apply-templates select="$tertiary.intersection"
222
                               mode="indexentry"/>
223
        </xsl:when>
224
        <xsl:when test="not(following-sibling::secondaryie)">
225
          <xsl:apply-templates select="following-sibling::tertiaryie"
226
                               mode="indexentry"/>
227
        </xsl:when>
228
      </xsl:choose>
229
    </dd>
230
  </dl>
231
</xsl:template>
232
233
<xsl:template match="tertiaryie" mode="indexentry">
234
  <dl>
235
    <dt>
236
      <xsl:apply-templates/>
237
    </dt>
238
    <dd>
239
      <!-- select following see* elements up to next secondaryie or tertiary or end -->
240
      <xsl:variable name="after.this"
241
              select="following-sibling::*"/>
242
      <xsl:variable name="next.entry"
243
              select="(following-sibling::secondaryie|following-sibling::tertiaryie)[1]"/>
244
      <xsl:variable name="before.entry"
245
                    select="$next.entry/preceding-sibling::*"/>
246
      <xsl:variable name="see.intersection"
247
             select="$after.this[count(.|$before.entry) = count($before.entry)]
248
                                [self::seeie or self::seealsoie]"/>
249
      <xsl:choose>
250
        <xsl:when test="count($see.intersection) != 0">
251
          <xsl:apply-templates select="$see.intersection" mode="indexentry"/>
252
        </xsl:when>
253
        <xsl:when test="count($next.entry) = 0">
254
          <xsl:apply-templates select="following-sibling::seeie"
255
                               mode="indexentry"/>
256
          <xsl:apply-templates select="following-sibling::seealsoie"
257
                               mode="indexentry"/>
258
        </xsl:when>
259
      </xsl:choose>
260
    </dd>
261
  </dl>
262
</xsl:template>
263
264
<xsl:template match="seeie" mode="indexentry">
265
  <dt>
266
    <xsl:text>(</xsl:text>
267
    <xsl:call-template name="gentext">
268
      <xsl:with-param name="key" select="'see'"/>
269
    </xsl:call-template>
270
    <xsl:text> </xsl:text>
271
    <xsl:apply-templates/>
272
    <xsl:text>)</xsl:text>
273
  </dt>
274
</xsl:template>
275
276
<xsl:template match="seealsoie" mode="indexentry">
277
  <div>
278
    <xsl:text>(</xsl:text>
279
    <xsl:call-template name="gentext">
280
      <xsl:with-param name="key" select="'seealso'"/>
281
    </xsl:call-template>
282
    <xsl:text> </xsl:text>
283
    <xsl:apply-templates/>
284
    <xsl:text>)</xsl:text>
285
  </div>
286
</xsl:template>
287
288
</xsl:stylesheet>