autoidx-kimber.xsl 6.6 KB

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