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