autoidx-kosek.xsl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?xml version="1.0"?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY % common.entities SYSTEM "entities.ent">
  4. %common.entities;
  5. ]>
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. version="1.0"
  8. xmlns:func="http://exslt.org/functions"
  9. xmlns:exslt="http://exslt.org/common"
  10. xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
  11. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  12. extension-element-prefixes="func exslt"
  13. exclude-result-prefixes="func exslt i l"
  14. xmlns:i="urn:cz-kosek:functions:index">
  15. <!-- ********************************************************************
  16. $Id: autoidx-kosek.xsl 8759 2010-07-20 21:46:07Z kosek $
  17. ********************************************************************
  18. This file is part of the DocBook XSL Stylesheet distribution.
  19. See ../README or http://docbook.sf.net/ for copyright
  20. copyright and other information.
  21. ******************************************************************** -->
  22. <xsl:param name="kosek.imported">
  23. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  24. <xsl:choose>
  25. <xsl:when test="contains($vendor, 'libxslt')">
  26. <xsl:message terminate="yes">
  27. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  28. <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
  29. </xsl:message>
  30. </xsl:when>
  31. <xsl:otherwise>1</xsl:otherwise>
  32. </xsl:choose>
  33. </xsl:param>
  34. <!-- Returns index group code for given term -->
  35. <func:function name="i:group-index">
  36. <xsl:param name="term"/>
  37. <xsl:variable name="letters-rtf">
  38. <xsl:variable name="lang">
  39. <xsl:call-template name="l10n.language"/>
  40. </xsl:variable>
  41. <xsl:variable name="local.l10n.letters"
  42. select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
  43. <xsl:for-each select="$l10n.xml">
  44. <xsl:variable name="l10n.letters"
  45. select="document(key('l10n-lang', $lang)/@href)/l:l10n/l:letters[1]"/>
  46. <xsl:choose>
  47. <xsl:when test="count($local.l10n.letters) &gt; 0">
  48. <xsl:copy-of select="$local.l10n.letters"/>
  49. </xsl:when>
  50. <xsl:when test="count($l10n.letters) &gt; 0">
  51. <xsl:copy-of select="$l10n.letters"/>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <xsl:message>
  55. <xsl:text>No "</xsl:text>
  56. <xsl:value-of select="$lang"/>
  57. <xsl:text>" localization of index grouping letters exists</xsl:text>
  58. <xsl:choose>
  59. <xsl:when test="$lang = 'en'">
  60. <xsl:text>.</xsl:text>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <xsl:text>; using "en".</xsl:text>
  64. </xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:message>
  67. <xsl:copy-of select="document(key('l10n-lang', 'en'))/l:l10n/l:letters[1]"/>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:for-each>
  71. </xsl:variable>
  72. <xsl:variable name="letters" select="exslt:node-set($letters-rtf)/*"/>
  73. <xsl:variable name="long-letter-index" select="$letters/l:l[. = substring($term,1,2)]/@i"/>
  74. <xsl:variable name="short-letter-index" select="$letters/l:l[. = substring($term,1,1)]/@i"/>
  75. <xsl:variable name="letter-index">
  76. <xsl:choose>
  77. <xsl:when test="$long-letter-index">
  78. <xsl:value-of select="$long-letter-index"/>
  79. </xsl:when>
  80. <xsl:when test="$short-letter-index">
  81. <xsl:value-of select="$short-letter-index"/>
  82. </xsl:when>
  83. <xsl:otherwise>0</xsl:otherwise>
  84. </xsl:choose>
  85. </xsl:variable>
  86. <func:result select="number($letter-index)"/>
  87. </func:function>
  88. <!-- Return index group letter for given group code -->
  89. <func:function name="i:group-letter">
  90. <xsl:param name="index"/>
  91. <xsl:variable name="letters-rtf">
  92. <xsl:variable name="lang">
  93. <xsl:call-template name="l10n.language"/>
  94. </xsl:variable>
  95. <xsl:variable name="local.l10n.letters"
  96. select="($local.l10n.xml//l:i18n/l:l10n[@language=$lang]/l:letters)[1]"/>
  97. <xsl:for-each select="$l10n.xml">
  98. <xsl:variable name="l10n.letters"
  99. select="document(key('l10n-lang', $lang)/@href)/l:l10n/l:letters[1]"/>
  100. <xsl:choose>
  101. <xsl:when test="count($local.l10n.letters) &gt; 0">
  102. <xsl:copy-of select="$local.l10n.letters"/>
  103. </xsl:when>
  104. <xsl:when test="count($l10n.letters) &gt; 0">
  105. <xsl:copy-of select="$l10n.letters"/>
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <xsl:message>
  109. <xsl:text>No "</xsl:text>
  110. <xsl:value-of select="$lang"/>
  111. <xsl:text>" localization of index grouping letters exists</xsl:text>
  112. <xsl:choose>
  113. <xsl:when test="$lang = 'en'">
  114. <xsl:text>.</xsl:text>
  115. </xsl:when>
  116. <xsl:otherwise>
  117. <xsl:text>; using "en".</xsl:text>
  118. </xsl:otherwise>
  119. </xsl:choose>
  120. </xsl:message>
  121. <xsl:copy-of select="document(key('l10n-lang', 'en')/@href)/l:l10n/l:letters[1]"/>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:for-each>
  125. </xsl:variable>
  126. <xsl:variable name="letters" select="exslt:node-set($letters-rtf)/*"/>
  127. <func:result select="$letters/l:l[@i=$index][1]"/>
  128. </func:function>
  129. <xsl:key name="group-code"
  130. match="indexterm"
  131. use="i:group-index(&primary;)"/>
  132. </xsl:stylesheet>