autoidx-kosek.xsl 5.1 KB

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