autoidx-kimber.xsl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?xml version="1.0"?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY % common.entities SYSTEM "../common/entities.ent">
  4. %common.entities;
  5. <!-- Documents using the kimber index method must have a lang attribute -->
  6. <!-- Only one of these should be present in the entity -->
  7. <!ENTITY lang 'concat(/*/@lang, /*/@xml:lang)'>
  8. ]>
  9. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  10. xmlns:k="http://www.isogen.com/functions/com.isogen.saxoni18n.Saxoni18nService"
  11. exclude-result-prefixes="k"
  12. version="1.0">
  13. <!-- ********************************************************************
  14. $Id: autoidx-kimber.xsl 8729 2010-07-15 16:43:56Z bobstayton $
  15. ********************************************************************
  16. This file is part of the XSL DocBook Stylesheet distribution.
  17. See ../README or http://docbook.sf.net/release/xsl/current/ for
  18. copyright and other information.
  19. ******************************************************************** -->
  20. <!-- ==================================================================== -->
  21. <!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen. -->
  22. <!-- ==================================================================== -->
  23. <!-- *** THIS MODULE ONLY WORKS WITH SAXON 6 OR SAXON 8 *** -->
  24. <!-- ==================================================================== -->
  25. <xsl:include href="../common/autoidx-kimber.xsl"/>
  26. <!-- Java sort apparently works only on lang part, not country -->
  27. <xsl:param name="sort.lang">
  28. <xsl:choose>
  29. <xsl:when test="contains(&lang;, '-')">
  30. <xsl:value-of select="substring-before(&lang;, '-')"/>
  31. </xsl:when>
  32. <xsl:when test="contains(&lang;, '_')">
  33. <xsl:value-of select="substring-before(&lang;, '_')"/>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <xsl:value-of select="&lang;"/>
  37. </xsl:otherwise>
  38. </xsl:choose>
  39. </xsl:param>
  40. <xsl:template name="generate-kimber-index">
  41. <xsl:param name="scope" select="NOTANODE"/>
  42. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  43. <xsl:if test="not(contains($vendor, 'SAXON '))">
  44. <xsl:message terminate="yes">
  45. <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
  46. <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
  47. </xsl:message>
  48. </xsl:if>
  49. <xsl:if test="not(function-available('k:getIndexGroupKey'))">
  50. <xsl:message terminate="yes">
  51. <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
  52. <xsl:text>Innodata Isogen &#x0A;Java extensions for </xsl:text>
  53. <xsl:text>internationalized indexes. &#x0A;Install those </xsl:text>
  54. <xsl:text>extensions, or use a different index method.&#x0A;</xsl:text>
  55. <xsl:text>For more information, see:&#x0A;</xsl:text>
  56. <xsl:text>http://www.innodata-isogen.com/knowledge_center/tools_downloads/i18nsupport</xsl:text>
  57. </xsl:message>
  58. </xsl:if>
  59. <xsl:variable name="role">
  60. <xsl:if test="$index.on.role != 0">
  61. <xsl:value-of select="@role"/>
  62. </xsl:if>
  63. </xsl:variable>
  64. <xsl:variable name="type">
  65. <xsl:if test="$index.on.type != 0">
  66. <xsl:value-of select="@type"/>
  67. </xsl:if>
  68. </xsl:variable>
  69. <xsl:variable name="terms"
  70. select="//indexterm[count(.|key('k-group', k:getIndexGroupKey(&lang;, &primary;))[&scope;][1]) = 1 and not(@class = 'endofrange')]"/>
  71. <xsl:variable name="alphabetical"
  72. select="$terms[not(starts-with(
  73. k:getIndexGroupKey(&lang;, &primary;),
  74. '#NUMERIC'
  75. ))]"/>
  76. <xsl:variable name="others"
  77. select="$terms[starts-with(
  78. k:getIndexGroupKey(&lang;, &primary;),
  79. '#NUMERIC'
  80. )]"/>
  81. <div class="index">
  82. <xsl:if test="$others">
  83. <div class="indexdev">
  84. <h3>
  85. <xsl:call-template name="gentext">
  86. <xsl:with-param name="key" select="'index symbols'"/>
  87. </xsl:call-template>
  88. </h3>
  89. <dl>
  90. <xsl:apply-templates select="$others"
  91. mode="index-symbol-div">
  92. <xsl:with-param name="scope" select="$scope"/>
  93. <xsl:with-param name="role" select="$role"/>
  94. <xsl:with-param name="type" select="$type"/>
  95. <xsl:sort lang="{$sort.lang}"
  96. select="k:getIndexGroupSortKey(&lang;,
  97. k:getIndexGroupKey(&lang;, &primary;))"/>
  98. </xsl:apply-templates>
  99. </dl>
  100. </div>
  101. </xsl:if>
  102. <xsl:apply-templates select="$alphabetical"
  103. mode="index-div-kimber">
  104. <xsl:with-param name="scope" select="$scope"/>
  105. <xsl:with-param name="role" select="$role"/>
  106. <xsl:with-param name="type" select="$type"/>
  107. <xsl:sort lang="{$sort.lang}"
  108. select="k:getIndexGroupSortKey(&lang;,
  109. k:getIndexGroupKey(&lang;, &primary;))"/>
  110. </xsl:apply-templates>
  111. </div>
  112. </xsl:template>
  113. <xsl:template match="indexterm" mode="index-div-kimber">
  114. <xsl:param name="scope" select="."/>
  115. <xsl:param name="role" select="''"/>
  116. <xsl:param name="type" select="''"/>
  117. <xsl:variable name="key"
  118. select="k:getIndexGroupKey(&lang;, &primary;)"/>
  119. <xsl:variable name="label"
  120. select="k:getIndexGroupLabel(&lang;, $key)"/>
  121. <xsl:if test="key('k-group', $label)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  122. <div class="indexdiv">
  123. <h3>
  124. <xsl:value-of select="$label"/>
  125. </h3>
  126. <dl>
  127. <xsl:apply-templates select="key('k-group', $key)[&scope;]
  128. [count(.|key('primary', &primary;)[&scope;]
  129. [1])=1]"
  130. mode="index-primary">
  131. <xsl:sort select="&primary;" lang="{$sort.lang}"/>
  132. <xsl:with-param name="scope" select="$scope"/>
  133. <xsl:with-param name="role" select="$role"/>
  134. <xsl:with-param name="type" select="$type"/>
  135. </xsl:apply-templates>
  136. </dl>
  137. </div>
  138. </xsl:if>
  139. </xsl:template>
  140. </xsl:stylesheet>