]> git.stg.codes - stg.git/blob - doc/xslt/common/autoidx-kosek.xsl
Use common functions in admin tests and service tests.
[stg.git] / doc / xslt / common / autoidx-kosek.xsl
1 <?xml version="1.0"?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY % common.entities SYSTEM "entities.ent">
4 %common.entities;
5 ]>
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7                 version="1.0"
8                 xmlns:func="http://exslt.org/functions"
9                 xmlns:exslt="http://exslt.org/common"
10                 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
11                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
12                 extension-element-prefixes="func exslt"
13                 exclude-result-prefixes="func exslt i l"
14                 xmlns:i="urn:cz-kosek:functions:index">
15
16 <!-- ********************************************************************
17      $Id: autoidx-kosek.xsl 8759 2010-07-20 21:46:07Z kosek $
18      ********************************************************************
19
20      This file is part of the DocBook XSL Stylesheet distribution.
21      See ../README or http://docbook.sf.net/ for copyright
22      copyright and other information.
23
24      ******************************************************************** -->
25
26 <xsl:param name="kosek.imported">
27   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
28   <xsl:choose>
29     <xsl:when test="contains($vendor, 'libxslt')">
30       <xsl:message terminate="yes">
31         <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
32         <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
33       </xsl:message>
34     </xsl:when>
35     <xsl:otherwise>1</xsl:otherwise>
36   </xsl:choose>
37 </xsl:param>
38
39 <!-- Returns index group code for given term  -->
40 <func:function name="i:group-index">
41   <xsl:param name="term"/>
42   
43   <xsl:variable name="letters-rtf">
44     <xsl:variable name="lang">
45       <xsl:call-template name="l10n.language"/>
46     </xsl:variable>
47     
48     <xsl:variable name="local.l10n.letters"
49       select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
50     
51     <xsl:for-each select="$l10n.xml">
52       <xsl:variable name="l10n.letters"
53         select="document(key('l10n-lang', $lang)/@href)/l:l10n/l:letters[1]"/>
54
55       <xsl:choose>
56         <xsl:when test="count($local.l10n.letters) &gt; 0">
57           <xsl:copy-of select="$local.l10n.letters"/>
58         </xsl:when>
59         <xsl:when test="count($l10n.letters) &gt; 0">
60           <xsl:copy-of select="$l10n.letters"/>
61         </xsl:when>
62         <xsl:otherwise>
63           <xsl:message>
64             <xsl:text>No "</xsl:text>
65             <xsl:value-of select="$lang"/>
66             <xsl:text>" localization of index grouping letters exists</xsl:text>
67             <xsl:choose>
68               <xsl:when test="$lang = 'en'">
69                 <xsl:text>.</xsl:text>
70               </xsl:when>
71               <xsl:otherwise>
72                 <xsl:text>; using "en".</xsl:text>
73               </xsl:otherwise>
74             </xsl:choose>
75           </xsl:message>
76
77           <xsl:copy-of select="document(key('l10n-lang', 'en'))/l:l10n/l:letters[1]"/>
78         </xsl:otherwise>
79       </xsl:choose>
80     </xsl:for-each>
81   </xsl:variable>
82   
83   <xsl:variable name="letters" select="exslt:node-set($letters-rtf)/*"/>
84   
85   <xsl:variable name="long-letter-index" select="$letters/l:l[. = substring($term,1,2)]/@i"/>
86   <xsl:variable name="short-letter-index" select="$letters/l:l[. = substring($term,1,1)]/@i"/>
87   <xsl:variable name="letter-index">
88     <xsl:choose>
89       <xsl:when test="$long-letter-index">
90         <xsl:value-of select="$long-letter-index"/>
91       </xsl:when>
92       <xsl:when test="$short-letter-index">
93         <xsl:value-of select="$short-letter-index"/>
94       </xsl:when>
95       <xsl:otherwise>0</xsl:otherwise>
96     </xsl:choose>
97   </xsl:variable>
98   <func:result select="number($letter-index)"/>
99 </func:function>
100
101 <!-- Return index group letter for given group code -->
102 <func:function name="i:group-letter">
103   <xsl:param name="index"/>
104
105   <xsl:variable name="letters-rtf">
106     <xsl:variable name="lang">
107       <xsl:call-template name="l10n.language"/>
108     </xsl:variable>
109     
110     <xsl:variable name="local.l10n.letters"
111       select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
112     
113     <xsl:for-each select="$l10n.xml">
114       <xsl:variable name="l10n.letters"
115         select="document(key('l10n-lang', $lang)/@href)/l:l10n/l:letters[1]"/>
116
117       <xsl:choose>
118         <xsl:when test="count($local.l10n.letters) &gt; 0">
119           <xsl:copy-of select="$local.l10n.letters"/>
120         </xsl:when>
121         <xsl:when test="count($l10n.letters) &gt; 0">
122           <xsl:copy-of select="$l10n.letters"/>
123         </xsl:when>
124         <xsl:otherwise>
125           <xsl:message>
126             <xsl:text>No "</xsl:text>
127             <xsl:value-of select="$lang"/>
128             <xsl:text>" localization of index grouping letters exists</xsl:text>
129             <xsl:choose>
130               <xsl:when test="$lang = 'en'">
131                 <xsl:text>.</xsl:text>
132               </xsl:when>
133               <xsl:otherwise>
134                 <xsl:text>; using "en".</xsl:text>
135               </xsl:otherwise>
136             </xsl:choose>
137           </xsl:message>
138
139           <xsl:copy-of select="document(key('l10n-lang', 'en')/@href)/l:l10n/l:letters[1]"/>
140         </xsl:otherwise>
141       </xsl:choose>
142     </xsl:for-each>
143   </xsl:variable>
144   
145   <xsl:variable name="letters" select="exslt:node-set($letters-rtf)/*"/>
146   
147   <func:result select="$letters/l:l[@i=$index][1]"/>
148 </func:function>
149
150 <xsl:key name="group-code"
151          match="indexterm"
152          use="i:group-index(&primary;)"/>
153
154 </xsl:stylesheet>