]> git.stg.codes - stg.git/blob - doc/xslt/fo/autoidx-kimber.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / fo / 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:fo="http://www.w3.org/1999/XSL/Format"
13                 xmlns:k="java:com.isogen.saxoni18n.Saxoni18nService"
14                 exclude-result-prefixes="k"
15                 version="1.0">
16
17 <!-- ********************************************************************
18      $Id: autoidx-kimber.xsl 8729 2010-07-15 16:43:56Z bobstayton $
19      ********************************************************************
20
21      This file is part of the DocBook XSL Stylesheet distribution.
22      See ../README or http://docbook.sf.net/ for copyright
23      copyright and other information.
24
25      ******************************************************************** -->
26
27 <!-- ==================================================================== -->
28 <!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen.  -->
29 <!-- ==================================================================== -->
30 <!--   *** THIS MODULE ONLY WORKS WITH SAXON 6 OR SAXON 8 ***             -->
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',
86                    k:getIndexGroupKey(&lang;, &primary;))
87                    [&scope;][1]) = 1
88                    and not(@class = 'endofrange')]"/>
89
90   <xsl:variable name="alphabetical"
91                 select="$terms[not(starts-with(
92                 k:getIndexGroupKey(&lang;, &primary;),
93                 '#NUMERIC'
94                 ))]"/>
95
96   <xsl:variable name="others"
97                 select="$terms[starts-with(
98                 k:getIndexGroupKey(&lang;, &primary;),
99                 '#NUMERIC'
100                 )]"/>
101
102   <fo:block>
103     <xsl:if test="$others">
104       <xsl:call-template name="indexdiv.title">
105         <xsl:with-param name="titlecontent">
106           <xsl:call-template name="gentext">
107             <xsl:with-param name="key" select="'index symbols'"/>
108           </xsl:call-template>
109         </xsl:with-param>
110       </xsl:call-template>
111
112       <fo:block>
113         <xsl:apply-templates select="$others"
114                              mode="index-symbol-div">
115           <xsl:with-param name="scope" select="$scope"/>
116           <xsl:with-param name="role" select="$role"/>
117           <xsl:with-param name="type" select="$type"/>
118           <xsl:sort lang="{$sort.lang}"
119               select="k:getIndexGroupSortKey(&lang;,
120                       k:getIndexGroupKey(&lang;, &primary;))"/>
121         </xsl:apply-templates>
122       </fo:block>
123     </xsl:if>
124
125     <xsl:apply-templates select="$alphabetical"
126                          mode="index-div-kimber">
127       <xsl:with-param name="scope" select="$scope"/>
128       <xsl:with-param name="role" select="$role"/>
129       <xsl:with-param name="type" select="$type"/>
130       <xsl:sort lang="{$sort.lang}"
131              select="k:getIndexGroupSortKey(&lang;,
132                      k:getIndexGroupKey(&lang;, &primary;))"/>
133     </xsl:apply-templates>
134   </fo:block>
135
136 </xsl:template>
137
138 <xsl:template match="indexterm" mode="index-div-kimber">
139   <xsl:param name="scope" select="."/>
140   <xsl:param name="role" select="''"/>
141   <xsl:param name="type" select="''"/>
142
143   <xsl:variable name="key"
144           select="k:getIndexGroupKey(&lang;, &primary;)"/>
145
146   <xsl:variable name="label"
147           select="k:getIndexGroupLabel(&lang;, $key)"/>
148
149   <xsl:if test="key('k-group', $key)[&scope;]
150                 [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
151     <fo:block>
152       <xsl:call-template name="indexdiv.title">
153         <xsl:with-param name="titlecontent">
154           <xsl:value-of select="$label"/>
155         </xsl:with-param>
156       </xsl:call-template>
157       <fo:block>
158         <xsl:apply-templates select="key('k-group', $key)[&scope;]
159                             [count(.|key('primary', &primary;)[&scope;]
160                             [1])=1]"
161                              mode="index-primary">
162           <xsl:sort select="&primary;" lang="{$sort.lang}"/>
163           <xsl:with-param name="scope" select="$scope"/>
164           <xsl:with-param name="role" select="$role"/>
165           <xsl:with-param name="type" select="$type"/>
166         </xsl:apply-templates>
167       </fo:block>
168     </fo:block>
169   </xsl:if>
170 </xsl:template>
171
172 </xsl:stylesheet>