]> git.stg.codes - stg.git/blob - doc/xslt/html/autoidx-kimber.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / html / autoidx-kimber.xsl
1 <?xml version="1.0"?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY % common.entities SYSTEM "../common/entities.ent">
4 %common.entities;
5
6 <!-- Documents using the kimber index method must have a lang attribute -->
7 <!-- Only one of these should be present in the entity -->
8 <!ENTITY lang 'concat(/*/@lang, /*/@xml:lang)'>
9
10 ]>
11 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12                 xmlns:k="http://www.isogen.com/functions/com.isogen.saxoni18n.Saxoni18nService"
13                 exclude-result-prefixes="k"
14                 version="1.0">
15
16 <!-- ********************************************************************
17      $Id: autoidx-kimber.xsl 8729 2010-07-15 16:43:56Z bobstayton $
18      ********************************************************************
19
20      This file is part of the XSL DocBook Stylesheet distribution.
21      See ../README or http://docbook.sf.net/release/xsl/current/ for
22      copyright and other information.
23
24      ******************************************************************** -->
25
26 <!-- ==================================================================== -->
27 <!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen.  -->
28 <!-- ==================================================================== -->
29 <!--   *** THIS MODULE ONLY WORKS WITH SAXON 6 OR SAXON 8 ***             -->
30 <!-- ==================================================================== -->
31
32
33 <xsl:include href="../common/autoidx-kimber.xsl"/>
34
35 <!-- Java sort apparently works only on lang part, not country -->
36 <xsl:param name="sort.lang">
37   <xsl:choose>
38     <xsl:when test="contains(&lang;, '-')">
39       <xsl:value-of select="substring-before(&lang;, '-')"/>
40     </xsl:when>
41     <xsl:when test="contains(&lang;, '_')">
42       <xsl:value-of select="substring-before(&lang;, '_')"/>
43     </xsl:when>
44     <xsl:otherwise>
45       <xsl:value-of select="&lang;"/>
46     </xsl:otherwise>
47   </xsl:choose>
48 </xsl:param>
49
50 <xsl:template name="generate-kimber-index">
51   <xsl:param name="scope" select="NOTANODE"/>
52
53   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
54   <xsl:if test="not(contains($vendor, 'SAXON '))">
55     <xsl:message terminate="yes">
56       <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
57       <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
58     </xsl:message>
59   </xsl:if>
60
61   <xsl:if test="not(function-available('k:getIndexGroupKey'))">
62     <xsl:message terminate="yes">
63       <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
64       <xsl:text>Innodata Isogen &#x0A;Java extensions for </xsl:text>
65       <xsl:text>internationalized indexes. &#x0A;Install those </xsl:text>
66       <xsl:text>extensions, or use a different index method.&#x0A;</xsl:text>
67       <xsl:text>For more information, see:&#x0A;</xsl:text>
68       <xsl:text>http://www.innodata-isogen.com/knowledge_center/tools_downloads/i18nsupport</xsl:text>
69     </xsl:message>
70   </xsl:if>
71
72   <xsl:variable name="role">
73     <xsl:if test="$index.on.role != 0">
74       <xsl:value-of select="@role"/>
75     </xsl:if>
76   </xsl:variable>
77
78   <xsl:variable name="type">
79     <xsl:if test="$index.on.type != 0">
80       <xsl:value-of select="@type"/>
81     </xsl:if>
82   </xsl:variable>
83
84   <xsl:variable name="terms"
85                 select="//indexterm[count(.|key('k-group', k:getIndexGroupKey(&lang;, &primary;))[&scope;][1]) = 1 and not(@class = 'endofrange')]"/>
86
87   <xsl:variable name="alphabetical"
88                 select="$terms[not(starts-with(
89                 k:getIndexGroupKey(&lang;, &primary;),
90                 '#NUMERIC'
91                 ))]"/>
92
93   <xsl:variable name="others"
94                 select="$terms[starts-with(
95                 k:getIndexGroupKey(&lang;, &primary;),
96                 '#NUMERIC'
97                 )]"/>
98
99   <div class="index">
100     <xsl:if test="$others">
101       <div class="indexdev">
102         <h3>
103           <xsl:call-template name="gentext">
104             <xsl:with-param name="key" select="'index symbols'"/>
105           </xsl:call-template>
106         </h3>
107         <dl>
108           <xsl:apply-templates select="$others"
109                                mode="index-symbol-div">
110             <xsl:with-param name="scope" select="$scope"/>
111             <xsl:with-param name="role" select="$role"/>
112             <xsl:with-param name="type" select="$type"/>
113             <xsl:sort lang="{$sort.lang}"
114                 select="k:getIndexGroupSortKey(&lang;,
115                         k:getIndexGroupKey(&lang;, &primary;))"/>
116           </xsl:apply-templates>
117         </dl>
118       </div>
119     </xsl:if>
120
121     <xsl:apply-templates select="$alphabetical"
122                          mode="index-div-kimber">
123       <xsl:with-param name="scope" select="$scope"/>
124       <xsl:with-param name="role" select="$role"/>
125       <xsl:with-param name="type" select="$type"/>
126       <xsl:sort lang="{$sort.lang}"
127              select="k:getIndexGroupSortKey(&lang;,
128                      k:getIndexGroupKey(&lang;, &primary;))"/>
129     </xsl:apply-templates>
130   </div>
131
132 </xsl:template>
133
134 <xsl:template match="indexterm" mode="index-div-kimber">
135   <xsl:param name="scope" select="."/>
136   <xsl:param name="role" select="''"/>
137   <xsl:param name="type" select="''"/>
138
139   <xsl:variable name="key"
140           select="k:getIndexGroupKey(&lang;, &primary;)"/>
141
142   <xsl:variable name="label"
143           select="k:getIndexGroupLabel(&lang;, $key)"/>
144
145   <xsl:if test="key('k-group', $label)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]">
146     <div class="indexdiv">
147       <h3>
148         <xsl:value-of select="$label"/>
149       </h3>
150       <dl>
151         <xsl:apply-templates select="key('k-group', $key)[&scope;]
152                             [count(.|key('primary', &primary;)[&scope;]
153                             [1])=1]"
154                              mode="index-primary">
155           <xsl:sort select="&primary;" lang="{$sort.lang}"/>
156           <xsl:with-param name="scope" select="$scope"/>
157           <xsl:with-param name="role" select="$role"/>
158           <xsl:with-param name="type" select="$type"/>
159         </xsl:apply-templates>
160       </dl>
161     </div>
162   </xsl:if>
163 </xsl:template>
164
165 </xsl:stylesheet>