Imported Upstream version 1.79.2
[platform/upstream/docbook-xsl-stylesheets.git] / 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:d="http://docbook.org/ns/docbook"
13                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
14                 xmlns:k="java:com.isogen.saxoni18n.Saxoni18nService"
15                 exclude-result-prefixes="k d"
16                 version="1.0">
17
18 <!-- ********************************************************************
19
20      This file is part of the DocBook XSL Stylesheet distribution.
21      See ../README or http://cdn.docbook.org/release/xsl for copyright
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 <xsl:include href="../common/autoidx-kimber.xsl"/>
33
34 <!-- Java sort apparently works only on lang part, not country -->
35 <xsl:param name="sort.lang">
36   <xsl:choose>
37     <xsl:when test="contains(&lang;, '-')">
38       <xsl:value-of select="substring-before(&lang;, '-')"/>
39     </xsl:when>
40     <xsl:when test="contains(&lang;, '_')">
41       <xsl:value-of select="substring-before(&lang;, '_')"/>
42     </xsl:when>
43     <xsl:otherwise>
44       <xsl:value-of select="&lang;"/>
45     </xsl:otherwise>
46   </xsl:choose>
47 </xsl:param>
48
49 <xsl:template name="generate-kimber-index">
50   <xsl:param name="scope" select="NOTANODE"/>
51
52   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
53   <xsl:if test="not(contains($vendor, 'SAXON '))">
54     <xsl:message terminate="yes">
55       <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
56       <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
57     </xsl:message>
58   </xsl:if>
59
60   <xsl:if test="not(function-available('k:getIndexGroupKey'))">
61     <xsl:message terminate="yes">
62       <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
63       <xsl:text>Innodata Isogen &#x0A;Java extensions for </xsl:text>
64       <xsl:text>internationalized indexes. &#x0A;Install those </xsl:text>
65       <xsl:text>extensions, or use a different index method.&#x0A;</xsl:text>
66       <xsl:text>For more information, see:&#x0A;</xsl:text>
67       <xsl:text>http://www.innodata-isogen.com/knowledge_center/tools_downloads/i18nsupport</xsl:text>
68     </xsl:message>
69   </xsl:if>
70
71   <xsl:variable name="role">
72     <xsl:if test="$index.on.role != 0">
73       <xsl:value-of select="@role"/>
74     </xsl:if>
75   </xsl:variable>
76
77   <xsl:variable name="type">
78     <xsl:if test="$index.on.type != 0">
79       <xsl:value-of select="@type"/>
80     </xsl:if>
81   </xsl:variable>
82
83   <xsl:variable name="terms"
84                 select="//d:indexterm[count(.|key('k-group',
85                    k:getIndexGroupKey(&lang;, &primary;))
86                    [&scope;][1]) = 1
87                    and not(@class = 'endofrange')]"/>
88
89   <xsl:variable name="alphabetical"
90                 select="$terms[not(starts-with(
91                 k:getIndexGroupKey(&lang;, &primary;),
92                 '#NUMERIC'
93                 ))]"/>
94
95   <xsl:variable name="others"
96                 select="$terms[starts-with(
97                 k:getIndexGroupKey(&lang;, &primary;),
98                 '#NUMERIC'
99                 )]"/>
100
101   <fo:block>
102     <xsl:if test="$others">
103       <xsl:call-template name="indexdiv.title">
104         <xsl:with-param name="titlecontent">
105           <xsl:call-template name="gentext">
106             <xsl:with-param name="key" select="'index symbols'"/>
107           </xsl:call-template>
108         </xsl:with-param>
109       </xsl:call-template>
110
111       <fo:block>
112         <xsl:apply-templates select="$others"
113                              mode="index-symbol-div">
114           <xsl:with-param name="scope" select="$scope"/>
115           <xsl:with-param name="role" select="$role"/>
116           <xsl:with-param name="type" select="$type"/>
117           <xsl:sort lang="{$sort.lang}"
118               select="k:getIndexGroupSortKey(&lang;,
119                       k:getIndexGroupKey(&lang;, &primary;))"/>
120         </xsl:apply-templates>
121       </fo:block>
122     </xsl:if>
123
124     <xsl:apply-templates select="$alphabetical"
125                          mode="index-div-kimber">
126       <xsl:with-param name="scope" select="$scope"/>
127       <xsl:with-param name="role" select="$role"/>
128       <xsl:with-param name="type" select="$type"/>
129       <xsl:sort lang="{$sort.lang}"
130              select="k:getIndexGroupSortKey(&lang;,
131                      k:getIndexGroupKey(&lang;, &primary;))"/>
132     </xsl:apply-templates>
133   </fo:block>
134
135 </xsl:template>
136
137 <xsl:template match="d:indexterm" mode="index-div-kimber">
138   <xsl:param name="scope" select="."/>
139   <xsl:param name="role" select="''"/>
140   <xsl:param name="type" select="''"/>
141
142   <xsl:variable name="key"
143           select="k:getIndexGroupKey(&lang;, &primary;)"/>
144
145   <xsl:variable name="label"
146           select="k:getIndexGroupLabel(&lang;, $key)"/>
147
148   <xsl:if test="key('k-group', $key)[&scope;]
149                 [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
150     <fo:block>
151       <xsl:call-template name="indexdiv.title">
152         <xsl:with-param name="titlecontent">
153           <xsl:value-of select="$label"/>
154         </xsl:with-param>
155       </xsl:call-template>
156       <fo:block>
157         <xsl:apply-templates select="key('k-group', $key)[&scope;]
158                             [count(.|key('primary', &primary;)[&scope;]
159                             [1])=1]"
160                              mode="index-primary">
161           <xsl:sort select="&primary;" lang="{$sort.lang}"/>
162           <xsl:with-param name="scope" select="$scope"/>
163           <xsl:with-param name="role" select="$role"/>
164           <xsl:with-param name="type" select="$type"/>
165         </xsl:apply-templates>
166       </fo:block>
167     </fo:block>
168   </xsl:if>
169 </xsl:template>
170
171 </xsl:stylesheet>