autoidx-kosek.xsl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?xml version="1.0"?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY % common.entities SYSTEM "../common/entities.ent">
  4. %common.entities;
  5. ]>
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  8. xmlns:rx="http://www.renderx.com/XSL/Extensions"
  9. xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
  10. xmlns:i="urn:cz-kosek:functions:index"
  11. xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
  12. xmlns:func="http://exslt.org/functions"
  13. xmlns:exslt="http://exslt.org/common"
  14. extension-element-prefixes="func exslt"
  15. exclude-result-prefixes="func exslt i l"
  16. version="1.0">
  17. <!-- ********************************************************************
  18. $Id: autoidx-kosek.xsl 8725 2010-07-15 08:08:04Z kosek $
  19. ********************************************************************
  20. This file is part of the DocBook XSL Stylesheet distribution.
  21. See ../README or http://docbook.sf.net/ for copyright
  22. copyright and other information.
  23. ******************************************************************** -->
  24. <!-- ==================================================================== -->
  25. <!-- The "kosek" method contributed by Jirka Kosek. -->
  26. <xsl:include href="../common/autoidx-kosek.xsl"/>
  27. <xsl:template name="generate-kosek-index">
  28. <xsl:param name="scope" select="NOTANODE"/>
  29. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  30. <xsl:if test="contains($vendor, 'libxslt')">
  31. <xsl:message terminate="yes">
  32. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  33. <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
  34. </xsl:message>
  35. </xsl:if>
  36. <xsl:if test="contains($vendor, 'Saxonica')">
  37. <xsl:message terminate="yes">
  38. <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
  39. <xsl:text>work with the Saxon 8 XSLT processor.</xsl:text>
  40. </xsl:message>
  41. </xsl:if>
  42. <xsl:if test="$exsl.node.set.available = 0">
  43. <xsl:message terminate="yes">
  44. <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
  45. <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
  46. <xsl:text>has it, or use a different index method.</xsl:text>
  47. </xsl:message>
  48. </xsl:if>
  49. <xsl:if test="not(function-available('i:group-index'))">
  50. <xsl:message terminate="yes">
  51. <xsl:text>ERROR: the 'kosek' index method requires the&#xA;</xsl:text>
  52. <xsl:text>index extension functions be imported:&#xA;</xsl:text>
  53. <xsl:text> xsl:import href="common/autoidx-kosek.xsl"</xsl:text>
  54. </xsl:message>
  55. </xsl:if>
  56. <xsl:variable name="role">
  57. <xsl:if test="$index.on.role != 0">
  58. <xsl:value-of select="@role"/>
  59. </xsl:if>
  60. </xsl:variable>
  61. <xsl:variable name="type">
  62. <xsl:if test="$index.on.type != 0">
  63. <xsl:value-of select="@type"/>
  64. </xsl:if>
  65. </xsl:variable>
  66. <xsl:variable name="terms"
  67. select="//indexterm[count(.|key('group-code',
  68. i:group-index(&primary;))
  69. [&scope;][1]) = 1
  70. and not(@class = 'endofrange')]"/>
  71. <fo:block>
  72. <xsl:apply-templates select="$terms" mode="index-div-kosek">
  73. <xsl:with-param name="scope" select="$scope"/>
  74. <xsl:with-param name="role" select="$role"/>
  75. <xsl:with-param name="type" select="$type"/>
  76. <xsl:sort select="i:group-index(&primary;)" data-type="number"/>
  77. </xsl:apply-templates>
  78. </fo:block>
  79. </xsl:template>
  80. <xsl:template match="indexterm" mode="index-div-kosek">
  81. <xsl:param name="scope" select="."/>
  82. <xsl:param name="role" select="''"/>
  83. <xsl:param name="type" select="''"/>
  84. <xsl:variable name="key"
  85. select="i:group-index(&primary;)"/>
  86. <xsl:variable name="lang">
  87. <xsl:call-template name="l10n.language"/>
  88. </xsl:variable>
  89. <xsl:if test="key('group-code', $key)[&scope;]
  90. [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
  91. <fo:block>
  92. <xsl:call-template name="indexdiv.title">
  93. <xsl:with-param name="titlecontent">
  94. <xsl:choose>
  95. <xsl:when test="$key = 0">
  96. <xsl:call-template name="gentext">
  97. <xsl:with-param name="key" select="'index symbols'"/>
  98. </xsl:call-template>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <xsl:value-of select="i:group-letter($key)"/>
  102. </xsl:otherwise>
  103. </xsl:choose>
  104. </xsl:with-param>
  105. </xsl:call-template>
  106. <fo:block>
  107. <xsl:apply-templates select="key('group-code', $key)[&scope;]
  108. [count(.|key('primary', &primary;)
  109. [&scope;][1])=1]"
  110. mode="index-primary">
  111. <xsl:sort select="&primary;" lang="{$lang}"/>
  112. <xsl:with-param name="scope" select="$scope"/>
  113. <xsl:with-param name="role" select="$role"/>
  114. <xsl:with-param name="type" select="$type"/>
  115. </xsl:apply-templates>
  116. </fo:block>
  117. </fo:block>
  118. </xsl:if>
  119. </xsl:template>
  120. </xsl:stylesheet>