]> granicus.if.org Git - docbook-dsssl/commitdiff
New modules for supporting indexing extensions.
authorBob Stayton <bobs@sagehill.net>
Wed, 30 Aug 2006 06:23:19 +0000 (06:23 +0000)
committerBob Stayton <bobs@sagehill.net>
Wed, 30 Aug 2006 06:23:19 +0000 (06:23 +0000)
xsl/common/autoidx-kimber.xsl [new file with mode: 0644]
xsl/common/autoidx-kosek.xsl [new file with mode: 0644]
xsl/html/autoidx-kimber.xsl [new file with mode: 0644]
xsl/html/autoidx-kosek.xsl [new file with mode: 0644]

diff --git a/xsl/common/autoidx-kimber.xsl b/xsl/common/autoidx-kimber.xsl
new file mode 100644 (file)
index 0000000..a1c4a1b
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<!DOCTYPE xsl:stylesheet [
+<!ENTITY primary   'normalize-space(concat(primary/@sortas, primary[not(@sortas)]))'>
+<!-- Documents using the kimber index method must have a lang attribute -->
+<!-- Only one of these should be present in the entity -->
+
+<!ENTITY lang 'concat(/*/@lang, /*/@xml:lang)'>
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="1.0"
+                xmlns:k="java:com.isogen.saxoni18n.Saxoni18nService"
+                exclude-result-prefixes="k">
+
+<!-- ********************************************************************
+     $Id$
+     ********************************************************************
+
+     This file is part of the DocBook XSL Stylesheet distribution.
+     See ../README or http://docbook.sf.net/ for copyright
+     and other information.
+
+     ******************************************************************** -->
+
+<xsl:param name="kimber.imported">
+  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
+  <xsl:choose>
+    <xsl:when test="not(contains($vendor, 'SAXON '))">
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
+        <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
+      </xsl:message>
+    </xsl:when>
+    <xsl:otherwise>1</xsl:otherwise>
+  </xsl:choose>
+</xsl:param>
+
+
+<!-- The following key used in the kimber indexing method. -->
+<xsl:key name="k-group"
+         match="indexterm"
+         use="k:getIndexGroupKey(&lang;, &primary;)"/>
+
+</xsl:stylesheet>
diff --git a/xsl/common/autoidx-kosek.xsl b/xsl/common/autoidx-kosek.xsl
new file mode 100644 (file)
index 0000000..6bcad77
--- /dev/null
@@ -0,0 +1,150 @@
+<?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"
+                xmlns:fo="http://www.w3.org/1999/XSL/Format"
+                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.
+
+     ******************************************************************** -->
+
+<xsl:param name="kosek.imported">
+  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
+  <xsl:choose>
+    <xsl:when test="contains($vendor, 'libxslt')">
+      <xsl:message terminate="yes">
+        <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
+        <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
+      </xsl:message>
+    </xsl:when>
+    <xsl:otherwise>1</xsl:otherwise>
+  </xsl:choose>
+</xsl:param>
+
+<!-- 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) &gt; 0">
+        <xsl:copy-of select="$local.l10n.letters"/>
+      </xsl:when>
+      <xsl:when test="count($l10n.letters) &gt; 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) &gt; 0">
+        <xsl:copy-of select="$local.l10n.letters"/>
+      </xsl:when>
+      <xsl:when test="count($l10n.letters) &gt; 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>
diff --git a/xsl/html/autoidx-kimber.xsl b/xsl/html/autoidx-kimber.xsl
new file mode 100644 (file)
index 0000000..5864d19
--- /dev/null
@@ -0,0 +1,159 @@
+<?xml version="1.0"?>
+<!DOCTYPE xsl:stylesheet [
+
+<!ENTITY primary   'normalize-space(concat(primary/@sortas, primary[not(@sortas) or @sortas = ""]))'>
+<!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas) or @sortas = ""]))'>
+<!ENTITY tertiary  'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas) or @sortas = ""]))'>
+
+<!-- Documents using the kimber index method must have a lang attribute -->
+<!-- Only one of these should be present in the entity -->
+<!ENTITY lang 'concat(/*/@lang, /*/@xml:lang)'>
+
+<!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())
+                and ($role = @role or $type = @type or
+                (string-length($role) = 0 and string-length($type) = 0))'>
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:k="java:com.isogen.saxoni18n.Saxoni18nService"
+                exclude-result-prefixes="k"
+                version="1.0">
+
+<!-- ********************************************************************
+     $Id$
+     ********************************************************************
+
+     This file is part of the XSL DocBook Stylesheet distribution.
+     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
+     and other information.
+
+     ******************************************************************** -->
+
+<!-- ==================================================================== -->
+<!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen.  -->
+<!-- ==================================================================== -->
+<!--   *** THIS MODULE ONLY WORKS WITH SAXON 6 OR SAXON 8 ***             -->
+<!-- ==================================================================== -->
+
+
+<xsl:include href="../common/autoidx-kimber.xsl"/>
+
+<xsl:template name="generate-kimber-index">
+  <xsl:param name="scope" select="NOTANODE"/>
+
+  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
+  <xsl:if test="not(contains($vendor, 'SAXON '))">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
+      <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:if test="not(function-available('k:getIndexGroupKey'))">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
+      <xsl:text>Innodata Isogen &#x0A;Java extensions for </xsl:text>
+      <xsl:text>internationalized indexes. &#x0A;Install those </xsl:text>
+      <xsl:text>extensions, or use a different index method.&#x0A;</xsl:text>
+      <xsl:text>For more information, see:&#x0A;</xsl:text>
+      <xsl:text>http://www.innodata-isogen.com/knowledge_center/tools_downloads/i18nsupport</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:variable name="role">
+    <xsl:if test="$index.on.role != 0">
+      <xsl:value-of select="@role"/>
+    </xsl:if>
+  </xsl:variable>
+
+  <xsl:variable name="type">
+    <xsl:if test="$index.on.type != 0">
+      <xsl:value-of select="@type"/>
+    </xsl:if>
+  </xsl:variable>
+
+  <xsl:variable name="terms"
+                select="//indexterm[count(.|key('k-group',
+                   k:getIndexGroupKey(&lang;, &primary;))
+                   [&scope;][1]) = 1
+                   and not(@class = 'endofrange')]"/>
+
+  <xsl:variable name="alphabetical"
+                select="$terms[not(starts-with(
+                k:getIndexGroupKey(&lang;, &primary;),
+                '#NUMERIC'
+                ))]"/>
+
+  <xsl:variable name="others"
+                select="$terms[starts-with(
+                k:getIndexGroupKey(&lang;, &primary;),
+                '#NUMERIC'
+                )]"/>
+
+  <div class="index">
+    <xsl:if test="$others">
+      <div class="indexdev">
+        <h3>
+          <xsl:call-template name="gentext">
+            <xsl:with-param name="key" select="'index symbols'"/>
+          </xsl:call-template>
+        </h3>
+        <dl>
+          <xsl:apply-templates select="$others"
+                               mode="index-symbol-div">
+            <xsl:with-param name="scope" select="$scope"/>
+            <xsl:with-param name="role" select="$role"/>
+            <xsl:with-param name="type" select="$type"/>
+            <xsl:sort lang="{&lang;}"
+                select="k:getIndexGroupSortKey(&lang;,
+                        k:getIndexGroupKey(&lang;, &primary;))"/>
+          </xsl:apply-templates>
+        </dl>
+      </div>
+    </xsl:if>
+
+    <xsl:apply-templates select="$alphabetical"
+                         mode="index-div-kimber">
+      <xsl:with-param name="scope" select="$scope"/>
+      <xsl:with-param name="role" select="$role"/>
+      <xsl:with-param name="type" select="$type"/>
+      <xsl:sort lang="{&lang;}"
+             select="k:getIndexGroupSortKey(&lang;,
+                     k:getIndexGroupKey(&lang;, &primary;))"/>
+    </xsl:apply-templates>
+  </div>
+
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-div-kimber">
+  <xsl:param name="scope" select="."/>
+  <xsl:param name="role" select="''"/>
+  <xsl:param name="type" select="''"/>
+
+  <xsl:variable name="key"
+          select="k:getIndexGroupKey(&lang;, &primary;)"/>
+
+  <xsl:variable name="label"
+          select="k:getIndexGroupLabel(&lang;, $key)"/>
+
+  <xsl:if test="key('k-group', $label)[&scope;]
+                [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
+    <div class="indexdiv">
+      <h3>
+        <xsl:value-of select="$label"/>
+      </h3>
+      <dl>
+        <xsl:apply-templates select="key('k-group', $key)[&scope;]
+                            [count(.|key('primary', &primary;)[&scope;]
+                            [1])=1]"
+                             mode="index-primary">
+          <xsl:sort select="&primary;" lang="{&lang;}"/>
+          <xsl:with-param name="scope" select="$scope"/>
+          <xsl:with-param name="role" select="$role"/>
+          <xsl:with-param name="type" select="$type"/>
+        </xsl:apply-templates>
+      </dl>
+    </div>
+  </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xsl/html/autoidx-kosek.xsl b/xsl/html/autoidx-kosek.xsl
new file mode 100644 (file)
index 0000000..e8f6335
--- /dev/null
@@ -0,0 +1,132 @@
+<?xml version="1.0"?>
+<!DOCTYPE xsl:stylesheet [
+
+<!ENTITY primary   'normalize-space(concat(primary/@sortas, primary[not(@sortas) or @sortas = ""]))'>
+<!ENTITY secondary 'normalize-space(concat(secondary/@sortas, secondary[not(@sortas) or @sortas = ""]))'>
+<!ENTITY tertiary  'normalize-space(concat(tertiary/@sortas, tertiary[not(@sortas) or @sortas = ""]))'>
+
+<!ENTITY scope 'count(ancestor::node()|$scope) = count(ancestor::node())
+                and ($role = @role or $type = @type or
+                (string-length($role) = 0 and string-length($type) = 0))'>
+]>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:i="urn:cz-kosek:functions:index"
+                xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
+                xmlns:func="http://exslt.org/functions"
+                xmlns:k="java:com.isogen.saxoni18n.Saxoni18nService"
+                xmlns:exslt="http://exslt.org/common"
+                extension-element-prefixes="func exslt"
+                exclude-result-prefixes="func exslt i l k"
+                version="1.0">
+
+<!-- ********************************************************************
+     $Id$
+     ********************************************************************
+
+     This file is part of the XSL DocBook Stylesheet distribution.
+     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
+     and other information.
+
+     ******************************************************************** -->
+
+<!-- ==================================================================== -->
+<!-- The "kosek" method contributed by Jirka Kosek. -->
+
+<xsl:include href="../common/autoidx-kosek.xsl"/>
+
+<xsl:template name="generate-kosek-index">
+  <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
+
+  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
+  <xsl:if test="contains($vendor, 'libxslt')">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
+      <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:if test="contains($vendor, 'Saxonica')">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
+      <xsl:text>work with the Saxon 8 XSLT processor.</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:if test="not(function-available('exslt:node-set') or
+                    function-available('exslt:nodeSet'))">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
+      <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
+      <xsl:text>has it, or use a different index method.</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:if test="not(function-available('i:group-index'))">
+    <xsl:message terminate="yes">
+      <xsl:text>ERROR: the 'kosek' index method requires the&#xA;</xsl:text>
+      <xsl:text>index extension functions be imported:&#xA;</xsl:text>
+      <xsl:text>  xsl:import href="common/autoidx-ng.xsl"</xsl:text>
+    </xsl:message>
+  </xsl:if>
+
+  <xsl:variable name="role">
+    <xsl:if test="$index.on.role != 0">
+      <xsl:value-of select="@role"/>
+    </xsl:if>
+  </xsl:variable>
+
+  <xsl:variable name="type">
+    <xsl:if test="$index.on.type != 0">
+      <xsl:value-of select="@type"/>
+    </xsl:if>
+  </xsl:variable>
+
+  <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-kosek">
+      <xsl:with-param name="scope" select="$scope"/>
+      <xsl:with-param name="role" select="$role"/>
+      <xsl:with-param name="type" select="$type"/>
+      <xsl:sort select="i:group-index(&primary;)" data-type="number"/>
+    </xsl:apply-templates>
+  </div>
+</xsl:template>
+
+<xsl:template match="indexterm" mode="index-div-kosek">
+  <xsl:param name="scope" select="."/>
+  <xsl:param name="role" select="''"/>
+  <xsl:param name="type" select="''"/>
+
+  <xsl:variable name="key"
+                select="i:group-index(&primary;)"/>
+
+  <xsl:variable name="lang">
+    <xsl:call-template name="l10n.language"/>
+  </xsl:variable>
+
+  <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="&primary;" lang="{$lang}"/>
+          <xsl:with-param name="scope" select="$scope"/>
+          <xsl:with-param name="role" select="$role"/>
+          <xsl:with-param name="type" select="$type"/>
+        </xsl:apply-templates>
+      </dl>
+    </div>
+  </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>