1
0

autoidx-kimber.xsl 6.2 KB

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