--- /dev/null
+<?xml version="1.0"?>
+<!DOCTYPE xsl:stylesheet [
+<!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0"
+ xmlns:func="http://exslt.org/functions"
+ xmlns:exslt="http://exslt.org/common"
+ xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
+ extension-element-prefixes="func exslt"
+ exclude-result-prefixes="func exslt i l"
+ xmlns:i="urn:cz-kosek:functions:index">
+
+<!-- ********************************************************************
+ $Id$
+ ********************************************************************
+
+ This file is part of the DocBook XSL Stylesheet distribution.
+ See ../README or http://docbook.sf.net/ for copyright
+ and other information.
+
+ ******************************************************************** -->
+
+<!-- Returns index group code for given term -->
+<func:function name="i:group-index">
+ <xsl:param name="term"/>
+
+ <xsl:variable name="letters-rtf">
+ <xsl:variable name="lang">
+ <xsl:call-template name="l10n.language"/>
+ </xsl:variable>
+
+ <xsl:variable name="local.l10n.letters"
+ select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
+
+ <xsl:variable name="l10n.letters"
+ select="($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
+
+ <xsl:choose>
+ <xsl:when test="count($local.l10n.letters) > 0">
+ <xsl:copy-of select="$local.l10n.letters"/>
+ </xsl:when>
+ <xsl:when test="count($l10n.letters) > 0">
+ <xsl:copy-of select="$l10n.letters"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>No "</xsl:text>
+ <xsl:value-of select="$lang"/>
+ <xsl:text>" localization of index grouping letters exists</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$lang = 'en'">
+ <xsl:text>.</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>; using "en".</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:message>
+
+ <xsl:copy-of select="($l10n.xml/l:i18n/l:l10n[@language='en']/l:letters)[1]"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="letters" select="exslt:node-set($letters-rtf)/*"/>
+
+ <xsl:variable name="long-letter-index" select="$letters/l:l[. = substring($term,1,2)]/@i"/>
+ <xsl:variable name="short-letter-index" select="$letters/l:l[. = substring($term,1,1)]/@i"/>
+ <xsl:variable name="letter-index">
+ <xsl:choose>
+ <xsl:when test="$long-letter-index">
+ <xsl:value-of select="$long-letter-index"/>
+ </xsl:when>
+ <xsl:when test="$short-letter-index">
+ <xsl:value-of select="$short-letter-index"/>
+ </xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <func:result select="number($letter-index)"/>
+</func:function>
+
+<!-- Return index group letter for given group code -->
+<func:function name="i:group-letter">
+ <xsl:param name="index"/>
+
+ <xsl:variable name="letters-rtf">
+ <xsl:variable name="lang">
+ <xsl:call-template name="l10n.language"/>
+ </xsl:variable>
+
+ <xsl:variable name="local.l10n.letters"
+ select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
+
+ <xsl:variable name="l10n.letters"
+ select="($l10n.xml/l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
+
+ <xsl:choose>
+ <xsl:when test="count($local.l10n.letters) > 0">
+ <xsl:copy-of select="$local.l10n.letters"/>
+ </xsl:when>
+ <xsl:when test="count($l10n.letters) > 0">
+ <xsl:copy-of select="$l10n.letters"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>No "</xsl:text>
+ <xsl:value-of select="$lang"/>
+ <xsl:text>" localization of index grouping letters exists</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$lang = 'en'">
+ <xsl:text>.</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>; using "en".</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:message>
+
+ <xsl:copy-of select="($l10n.xml/l:i18n/l:l10n[@language='en']/l:letters)[1]"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="letters" select="exslt:node-set($letters-rtf)/*"/>
+
+ <func:result select="$letters/l:l[@i=$index][1]"/>
+</func:function>
+
+<xsl:key name="group-code"
+ match="indexterm"
+ use="i:group-index(&primary;)"/>
+
+</xsl:stylesheet>
<!ENTITY % dingbat "%prefix;:dingbat">
<!ENTITY % context "%prefix;:context">
<!ENTITY % template "%prefix;:template">
+<!ENTITY % letters "%prefix;:letters">
+<!ENTITY % l "%prefix;:l">
+<!ENTITY % lang "lang NMTOKEN #IMPLIED">
<!ELEMENT %i18n; ((%l10n;)+)>
<!ATTLIST %i18n;
%xmlns; CDATA #FIXED %uri;
>
-<!ELEMENT %l10n; (%gentext;|%dingbat;|%context;)*>
+<!ELEMENT %l10n; (%gentext;|%dingbat;|%context;|%letters;)*>
<!ATTLIST %l10n;
%xmlns; CDATA #FIXED %uri;
language CDATA #REQUIRED
<!ELEMENT %gentext; EMPTY>
<!ATTLIST %gentext;
+ %lang;
key CDATA #REQUIRED
text CDATA #REQUIRED
>
<!ELEMENT %dingbat; EMPTY>
<!ATTLIST %dingbat;
+ %lang;
key CDATA #REQUIRED
text CDATA #REQUIRED
>
<!ELEMENT %template; EMPTY>
<!ATTLIST %template;
+ %lang;
name CDATA #REQUIRED
text CDATA #REQUIRED
style CDATA #IMPLIED
>
+
+<!ELEMENT %letters; ((%l;)+)>
+<!ATTLIST %letters;
+ %lang;
+>
+
+<!ELEMENT %l; (#PCDATA)>
+<!ATTLIST %l;
+ i CDATA #REQUIRED
+>
--- /dev/null
+<?xml version="1.0"?>
+<!DOCTYPE xsl:stylesheet [
+
+<!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
+<!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
+
+<!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
+<!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas)]))'>
+<!ENTITY tertiary 'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas)]))'>
+
+<!ENTITY sep '" "'>
+<!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())'>
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ version="1.0"
+ xmlns:func="http://exslt.org/functions"
+ exclude-result-prefixes="i"
+ xmlns:i="urn:cz-kosek:functions:index">
+
+<!-- ********************************************************************
+ $Id$
+ ********************************************************************
+
+ This file is part of the DocBook XSL Stylesheet distribution.
+ See ../README or http://docbook.sf.net/ for copyright
+ and other information.
+
+ ******************************************************************** -->
+
+<xsl:include href="../common/autoidx-ng.xsl"/>
+
+<!-- Modified original code is using index group codes instead of just first letter
+ to gain better grouping -->
+<xsl:template name="generate-index">
+ <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
+
+ <xsl:variable name="terms"
+ select="//indexterm[count(.|key('group-code',
+ i:group-index(&primary;))[&scope;][1]) = 1
+ and not(@class = 'endofrange')]"/>
+
+ <xsl:apply-templates select="$terms" mode="index-div">
+ <xsl:with-param name="scope" select="$scope"/>
+ <xsl:sort select="i:group-index(&primary;)" data-type="number"/>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-div">
+ <xsl:param name="scope" select="."/>
+
+ <xsl:variable name="key"
+ select="i:group-index(&primary;)"/>
+
+ <xsl:if test="key('group-code', $key)[&scope;]
+ [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
+ <fo:block>
+ <xsl:call-template name="indexdiv.title">
+ <xsl:with-param name="titlecontent">
+ <xsl:value-of select="i:group-letter($key)"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <fo:block>
+ <xsl:apply-templates select="key('group-code', $key)[&scope;]
+ [count(.|key('primary', &primary;)[&scope;][1])=1]"
+ mode="index-primary">
+ <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
+ <xsl:with-param name="scope" select="$scope"/>
+ </xsl:apply-templates>
+ </fo:block>
+ </fo:block>
+ </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
--- /dev/null
+<?xml version="1.0"?>
+<!DOCTYPE xsl:stylesheet [
+
+<!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
+<!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
+
+<!ENTITY primary 'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
+<!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas)]))'>
+<!ENTITY tertiary 'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas)]))'>
+
+<!ENTITY sep '" "'>
+<!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())'>
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ version="1.0"
+ xmlns:func="http://exslt.org/functions"
+ exclude-result-prefixes="i"
+ xmlns:i="urn:cz-kosek:functions:index">
+
+<!-- ********************************************************************
+ $Id$
+ ********************************************************************
+
+ This file is part of the DocBook XSL Stylesheet distribution.
+ See ../README or http://docbook.sf.net/ for copyright
+ and other information.
+
+ ******************************************************************** -->
+
+<xsl:include href="../common/autoidx-ng.xsl"/>
+
+<!-- Modified original code is using index group codes instead of just first letter
+ to gain better grouping -->
+<xsl:template name="generate-index">
+ <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
+
+ <xsl:variable name="terms"
+ select="//indexterm[count(.|key('group-code',
+ i:group-index(&primary;))[&scope;][1]) = 1
+ and not(@class = 'endofrange')]"/>
+
+ <div class="index">
+ <xsl:apply-templates select="$terms" mode="index-div">
+ <xsl:with-param name="scope" select="$scope"/>
+ <xsl:sort select="i:group-index(&primary;)" data-type="number"/>
+ </xsl:apply-templates>
+ </div>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-div">
+ <xsl:param name="scope" select="."/>
+
+ <xsl:variable name="key"
+ select="i:group-index(&primary;)"/>
+
+ <xsl:if test="key('group-code', $key)[&scope;]
+ [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
+ <div class="indexdiv">
+ <h3>
+ <xsl:value-of select="i:group-letter($key)"/>
+ </h3>
+ <dl>
+ <xsl:apply-templates select="key('group-code', $key)[&scope;]
+ [count(.|key('primary', &primary;)[&scope;][1])=1]"
+ mode="index-primary">
+ <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
+ <xsl:with-param name="scope" select="$scope"/>
+ </xsl:apply-templates>
+ </dl>
+ </div>
+ </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>