]> git.stg.codes - stg.git/blob - doc/xslt/html/autoidx-kosek.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / html / autoidx-kosek.xsl
1 <?xml version="1.0"?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY % common.entities SYSTEM "../common/entities.ent">
4 %common.entities;
5 ]>
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7                 xmlns:i="urn:cz-kosek:functions:index"
8                 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
9                 xmlns:func="http://exslt.org/functions"
10                 xmlns:k="http://www.isogen.com/functions/com.isogen.saxoni18n.Saxoni18nService"
11                 xmlns:exslt="http://exslt.org/common"
12                 extension-element-prefixes="func exslt"
13                 exclude-result-prefixes="func exslt i l k"
14                 version="1.0">
15
16 <!-- ********************************************************************
17      $Id: autoidx-kosek.xsl 8725 2010-07-15 08:08:04Z kosek $
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 "kosek" method contributed by Jirka Kosek. -->
28
29 <xsl:include href="../common/autoidx-kosek.xsl"/>
30
31 <xsl:template name="generate-kosek-index">
32   <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
33
34   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
35   <xsl:if test="contains($vendor, 'libxslt')">
36     <xsl:message terminate="yes">
37       <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
38       <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
39     </xsl:message>
40   </xsl:if>
41
42   <xsl:if test="contains($vendor, 'Saxonica')">
43     <xsl:message terminate="yes">
44       <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
45       <xsl:text>work with the Saxon 8 XSLT processor.</xsl:text>
46     </xsl:message>
47   </xsl:if>
48
49   <xsl:if test="$exsl.node.set.available = 0">
50     <xsl:message terminate="yes">
51       <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
52       <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
53       <xsl:text>has it, or use a different index method.</xsl:text>
54     </xsl:message>
55   </xsl:if>
56
57   <xsl:if test="not(function-available('i:group-index'))">
58     <xsl:message terminate="yes">
59       <xsl:text>ERROR: the 'kosek' index method requires the&#xA;</xsl:text>
60       <xsl:text>index extension functions be imported:&#xA;</xsl:text>
61       <xsl:text>  xsl:import href="common/autoidx-kosek.xsl"</xsl:text>
62     </xsl:message>
63   </xsl:if>
64
65   <xsl:variable name="role">
66     <xsl:if test="$index.on.role != 0">
67       <xsl:value-of select="@role"/>
68     </xsl:if>
69   </xsl:variable>
70
71   <xsl:variable name="type">
72     <xsl:if test="$index.on.type != 0">
73       <xsl:value-of select="@type"/>
74     </xsl:if>
75   </xsl:variable>
76
77   <xsl:variable name="terms"
78                 select="//indexterm[count(.|key('group-code', i:group-index(&primary;))[&scope;][1]) = 1 and not(@class = 'endofrange')]"/>
79
80   <div class="index">
81     <xsl:apply-templates select="$terms" mode="index-div-kosek">
82       <xsl:with-param name="scope" select="$scope"/>
83       <xsl:with-param name="role" select="$role"/>
84       <xsl:with-param name="type" select="$type"/>
85       <xsl:sort select="i:group-index(&primary;)" data-type="number"/>
86     </xsl:apply-templates>
87   </div>
88 </xsl:template>
89
90 <xsl:template match="indexterm" mode="index-div-kosek">
91   <xsl:param name="scope" select="."/>
92   <xsl:param name="role" select="''"/>
93   <xsl:param name="type" select="''"/>
94
95   <xsl:variable name="key"
96                 select="i:group-index(&primary;)"/>
97
98   <xsl:variable name="lang">
99     <xsl:call-template name="l10n.language"/>
100   </xsl:variable>
101
102   <xsl:if test="key('group-code', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]">
103     <div class="indexdiv">
104       <h3>
105         <xsl:value-of select="i:group-letter($key)"/>
106       </h3>
107       <dl>
108         <xsl:apply-templates select="key('group-code', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1])=1]"
109                              mode="index-primary">
110           <xsl:sort select="&primary;" lang="{$lang}"/>
111           <xsl:with-param name="scope" select="$scope"/>
112           <xsl:with-param name="role" select="$role"/>
113           <xsl:with-param name="type" select="$type"/>
114         </xsl:apply-templates>
115       </dl>
116     </div>
117   </xsl:if>
118 </xsl:template>
119
120 </xsl:stylesheet>