2 <!DOCTYPE xsl:stylesheet [
 
   3 <!ENTITY % common.entities SYSTEM "../common/entities.ent">
 
   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:exslt="http://exslt.org/common"
 
  11                 extension-element-prefixes="exslt"
 
  12                 exclude-result-prefixes="exslt"
 
  15 <!-- ********************************************************************
 
  16      $Id: autoidx.xsl 8399 2009-04-08 07:37:42Z bobstayton $
 
  17      ********************************************************************
 
  19      This file is part of the DocBook XSL Stylesheet distribution.
 
  20      See ../README or http://docbook.sf.net/ for copyright
 
  21      copyright and other information.
 
  23      ******************************************************************** -->
 
  25 <!-- ==================================================================== -->
 
  26 <!-- The "basic" method derived from Jeni Tennison's work. -->
 
  27 <!-- The "kosek" method contributed by Jirka Kosek. -->
 
  28 <!-- The "kimber" method contributed by Eliot Kimber of Innodata Isogen. -->
 
  30 <!-- Importing module for kimber or kosek method overrides one of these -->
 
  31 <xsl:param name="kimber.imported" select="0"/>
 
  32 <xsl:param name="kosek.imported" select="0"/>
 
  34 <!-- These keys used primary in all methods -->
 
  35 <xsl:key name="letter"
 
  37          use="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
 
  39 <xsl:key name="primary"
 
  43 <xsl:key name="secondary"
 
  45          use="concat(&primary;, &sep;, &secondary;)"/>
 
  47 <xsl:key name="tertiary"
 
  49          use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
 
  51 <xsl:key name="endofrange"
 
  52          match="indexterm[@class='endofrange']"
 
  55 <xsl:key name="see-also"
 
  56          match="indexterm[seealso]"
 
  57          use="concat(&primary;, &sep;, 
 
  59                      &tertiary;, &sep;, seealso)"/>
 
  62          match="indexterm[see]"
 
  63          use="concat(&primary;, &sep;, 
 
  65                      &tertiary;, &sep;, see)"/>
 
  68 <xsl:template name="generate-index">
 
  69   <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
 
  72     <xsl:when test="$index.method = 'kosek'">
 
  73       <xsl:call-template name="generate-kosek-index">
 
  74         <xsl:with-param name="scope" select="$scope"/>
 
  77     <xsl:when test="$index.method = 'kimber'">
 
  78       <xsl:call-template name="generate-kimber-index">
 
  79         <xsl:with-param name="scope" select="$scope"/>
 
  84       <xsl:call-template name="generate-basic-index">
 
  85         <xsl:with-param name="scope" select="$scope"/>
 
  91 <xsl:template name="generate-basic-index">
 
  92   <xsl:param name="scope" select="NOTANODE"/>
 
  94   <xsl:variable name="role">
 
  95     <xsl:if test="$index.on.role != 0">
 
  96       <xsl:value-of select="@role"/>
 
 100   <xsl:variable name="type">
 
 101     <xsl:if test="$index.on.type != 0">
 
 102       <xsl:value-of select="@type"/>
 
 106   <xsl:variable name="terms"
 
 108                         [count(.|key('letter',
 
 109                           translate(substring(&primary;, 1, 1),
 
 113                           and not(@class = 'endofrange')]"/>
 
 115   <xsl:variable name="alphabetical"
 
 116                 select="$terms[contains(concat(&lowercase;, &uppercase;),
 
 117                                         substring(&primary;, 1, 1))]"/>
 
 119   <xsl:variable name="others" select="$terms[not(contains(
 
 122                                         substring(&primary;, 1, 1)))]"/>
 
 124     <xsl:if test="$others">
 
 125       <xsl:call-template name="indexdiv.title">
 
 126         <xsl:with-param name="titlecontent">
 
 127           <xsl:call-template name="gentext">
 
 128             <xsl:with-param name="key" select="'index symbols'"/>
 
 134         <xsl:apply-templates select="$others[count(.|key('primary',
 
 135                                      &primary;)[&scope;][1]) = 1]"
 
 136                              mode="index-symbol-div">
 
 137           <xsl:with-param name="scope" select="$scope"/>
 
 138           <xsl:with-param name="role" select="$role"/>
 
 139           <xsl:with-param name="type" select="$type"/>
 
 140           <xsl:sort select="translate(&primary;, &lowercase;, 
 
 142         </xsl:apply-templates>
 
 146     <xsl:apply-templates select="$alphabetical[count(.|key('letter',
 
 147                                  translate(substring(&primary;, 1, 1),
 
 148                                            &lowercase;,&uppercase;))
 
 150                          mode="index-div-basic">
 
 151       <xsl:with-param name="scope" select="$scope"/>
 
 152       <xsl:with-param name="role" select="$role"/>
 
 153       <xsl:with-param name="type" select="$type"/>
 
 154       <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 155     </xsl:apply-templates>
 
 159 <!-- This template not used if fo/autoidx-kosek.xsl is imported -->
 
 160 <xsl:template name="generate-kosek-index">
 
 161   <xsl:param name="scope" select="NOTANODE"/>
 
 163   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
 
 164   <xsl:if test="contains($vendor, 'libxslt')">
 
 165     <xsl:message terminate="yes">
 
 166       <xsl:text>ERROR: the 'kosek' index method does not </xsl:text>
 
 167       <xsl:text>work with the xsltproc XSLT processor.</xsl:text>
 
 172   <xsl:if test="$exsl.node.set.available = 0">
 
 173     <xsl:message terminate="yes">
 
 174       <xsl:text>ERROR: the 'kosek' index method requires the </xsl:text>
 
 175       <xsl:text>exslt:node-set() function. Use a processor that </xsl:text>
 
 176       <xsl:text>has it, or use a different index method.</xsl:text>
 
 180   <xsl:if test="$kosek.imported = 0">
 
 181     <xsl:message terminate="yes">
 
 182       <xsl:text>ERROR: the 'kosek' index method requires the
</xsl:text>
 
 183       <xsl:text>kosek index extensions be imported:
</xsl:text>
 
 184       <xsl:text>  xsl:import href="fo/autoidx-kosek.xsl"</xsl:text>
 
 191 <!-- This template not used if fo/autoidx-kimber.xsl is imported -->
 
 192 <xsl:template name="generate-kimber-index">
 
 193   <xsl:param name="scope" select="NOTANODE"/>
 
 195   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
 
 196   <xsl:if test="not(contains($vendor, 'SAXON '))">
 
 197     <xsl:message terminate="yes">
 
 198       <xsl:text>ERROR: the 'kimber' index method requires the </xsl:text>
 
 199       <xsl:text>Saxon version 6 or 8 XSLT processor.</xsl:text>
 
 203   <xsl:if test="$kimber.imported = 0">
 
 204     <xsl:message terminate="yes">
 
 205       <xsl:text>ERROR: the 'kimber' index method requires the
</xsl:text>
 
 206       <xsl:text>kimber index extensions be imported:
</xsl:text>
 
 207       <xsl:text>  xsl:import href="fo/autoidx-kimber.xsl"</xsl:text>
 
 213 <xsl:template match="indexterm" mode="index-div-basic">
 
 214   <xsl:param name="scope" select="."/>
 
 215   <xsl:param name="role" select="''"/>
 
 216   <xsl:param name="type" select="''"/>
 
 218   <xsl:variable name="key"
 
 219                 select="translate(substring(&primary;, 1, 1),
 
 220                          &lowercase;,&uppercase;)"/>
 
 222   <xsl:if test="key('letter', $key)[&scope;]
 
 223                 [count(.|key('primary', &primary;)[&scope;][1]) = 1]">
 
 225       <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
 
 226         <xsl:call-template name="indexdiv.title">
 
 227           <xsl:with-param name="titlecontent">
 
 228             <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
 
 232       <fo:block xsl:use-attribute-sets="index.entry.properties">
 
 233         <xsl:apply-templates select="key('letter', $key)[&scope;]
 
 234                                      [count(.|key('primary', &primary;)
 
 236                              mode="index-primary">
 
 237           <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 238           <xsl:with-param name="scope" select="$scope"/>
 
 239           <xsl:with-param name="role" select="$role"/>
 
 240           <xsl:with-param name="type" select="$type"/>
 
 241         </xsl:apply-templates>
 
 247 <xsl:template match="indexterm" mode="index-symbol-div">
 
 248   <xsl:param name="scope" select="."/>
 
 249   <xsl:param name="role" select="''"/>
 
 250   <xsl:param name="type" select="''"/>
 
 252   <xsl:variable name="key"
 
 253                 select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
 
 255   <fo:block xsl:use-attribute-sets="index.entry.properties">
 
 256     <xsl:apply-templates select="key('letter', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]"
 
 257                          mode="index-primary">
 
 258       <xsl:with-param name="scope" select="$scope"/>
 
 259       <xsl:with-param name="role" select="$role"/>
 
 260       <xsl:with-param name="type" select="$type"/>
 
 261       <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 262     </xsl:apply-templates>
 
 266 <xsl:template match="indexterm" mode="index-primary">
 
 267   <xsl:param name="scope" select="."/>
 
 268   <xsl:param name="role" select="''"/>
 
 269   <xsl:param name="type" select="''"/>
 
 271   <xsl:variable name="key" select="&primary;"/>
 
 272   <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
 
 274   <xsl:variable name="term.separator">
 
 275     <xsl:call-template name="index.separator">
 
 276       <xsl:with-param name="key" select="'index.term.separator'"/>
 
 280   <xsl:variable name="range.separator">
 
 281     <xsl:call-template name="index.separator">
 
 282       <xsl:with-param name="key" select="'index.range.separator'"/>
 
 286   <xsl:variable name="number.separator">
 
 287     <xsl:call-template name="index.separator">
 
 288       <xsl:with-param name="key" select="'index.number.separator'"/>
 
 293     <xsl:if test="$axf.extensions != 0">
 
 294       <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
 
 297     <xsl:for-each select="$refs/primary">
 
 298       <xsl:if test="@id or @xml:id">
 
 299         <fo:inline id="{(@id|@xml:id)[1]}"/>
 
 303     <xsl:value-of select="primary"/>
 
 306       <xsl:when test="$xep.extensions != 0">
 
 307         <xsl:if test="$refs[not(see) and not(secondary)]">
 
 308           <xsl:copy-of select="$term.separator"/>
 
 309           <xsl:variable name="primary" select="&primary;"/>
 
 310           <xsl:variable name="primary.significant" select="concat(&primary;, $significant.flag)"/>
 
 311           <rx:page-index list-separator="{$number.separator}"
 
 312                          range-separator="{$range.separator}">
 
 313             <xsl:if test="$refs[@significance='preferred'][not(see) and not(secondary)]">
 
 314               <rx:index-item xsl:use-attribute-sets="index.preferred.page.properties xep.index.item.properties"
 
 315                 ref-key="{$primary.significant}"/>
 
 317             <xsl:if test="$refs[not(@significance) or @significance!='preferred'][not(see) and not(secondary)]">
 
 318               <rx:index-item xsl:use-attribute-sets="xep.index.item.properties"
 
 319                 ref-key="{$primary}"/>
 
 325         <xsl:variable name="page-number-citations">
 
 326           <xsl:for-each select="$refs[not(see) 
 
 327                                 and not(secondary)]">
 
 328             <xsl:apply-templates select="." mode="reference">
 
 329               <xsl:with-param name="scope" select="$scope"/>
 
 330               <xsl:with-param name="role" select="$role"/>
 
 331               <xsl:with-param name="type" select="$type"/>
 
 332               <xsl:with-param name="position" select="position()"/>
 
 333             </xsl:apply-templates>
 
 338           <xsl:when test="$passivetex.extensions != '0'">
 
 339             <fotex:sort xmlns:fotex="http://www.tug.org/fotex">
 
 340               <xsl:copy-of select="$page-number-citations"/>
 
 344             <xsl:copy-of select="$page-number-citations"/>
 
 350     <xsl:if test="$refs[not(secondary)]/*[self::see]">
 
 351       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[&scope;][1])]"
 
 353          <xsl:with-param name="scope" select="$scope"/>
 
 354          <xsl:with-param name="role" select="$role"/>
 
 355          <xsl:with-param name="type" select="$type"/>
 
 356          <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
 
 357       </xsl:apply-templates>
 
 362   <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::seealso]">
 
 363     <fo:block start-indent="1pc">
 
 364       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[&scope;][1])]"
 
 365                            mode="index-seealso">
 
 366          <xsl:with-param name="scope" select="$scope"/>
 
 367          <xsl:with-param name="role" select="$role"/>
 
 368          <xsl:with-param name="type" select="$type"/>
 
 369          <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
 
 370       </xsl:apply-templates>
 
 371       <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[&scope;][1]) = 1]"
 
 372                            mode="index-secondary">
 
 373        <xsl:with-param name="scope" select="$scope"/>
 
 374        <xsl:with-param name="role" select="$role"/>
 
 375        <xsl:with-param name="type" select="$type"/>
 
 376        <xsl:sort select="translate(&secondary;, &lowercase;, &uppercase;)"/>
 
 377       </xsl:apply-templates>
 
 382 <xsl:template match="indexterm" mode="index-secondary">
 
 383   <xsl:param name="scope" select="."/>
 
 384   <xsl:param name="role" select="''"/>
 
 385   <xsl:param name="type" select="''"/>
 
 387   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
 
 388   <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
 
 390   <xsl:variable name="term.separator">
 
 391     <xsl:call-template name="index.separator">
 
 392       <xsl:with-param name="key" select="'index.term.separator'"/>
 
 396   <xsl:variable name="range.separator">
 
 397     <xsl:call-template name="index.separator">
 
 398       <xsl:with-param name="key" select="'index.range.separator'"/>
 
 402   <xsl:variable name="number.separator">
 
 403     <xsl:call-template name="index.separator">
 
 404       <xsl:with-param name="key" select="'index.number.separator'"/>
 
 409     <xsl:if test="$axf.extensions != 0">
 
 410       <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
 
 413     <xsl:for-each select="$refs/secondary">
 
 414       <xsl:if test="@id or @xml:id">
 
 415         <fo:inline id="{(@id|@xml:id)[1]}"/>
 
 419     <xsl:value-of select="secondary"/>
 
 422       <xsl:when test="$xep.extensions != 0">
 
 423         <xsl:if test="$refs[not(see) and not(tertiary)]">
 
 424           <xsl:copy-of select="$term.separator"/>
 
 425           <xsl:variable name="primary" select="&primary;"/>
 
 426           <xsl:variable name="secondary" select="&secondary;"/>
 
 427           <xsl:variable name="primary.significant" select="concat(&primary;, $significant.flag)"/>
 
 428           <rx:page-index list-separator="{$number.separator}"
 
 429                          range-separator="{$range.separator}">
 
 430             <xsl:if test="$refs[@significance='preferred'][not(see) and not(tertiary)]">
 
 431               <rx:index-item xsl:use-attribute-sets="index.preferred.page.properties xep.index.item.properties">
 
 432                 <xsl:attribute name="ref-key">
 
 433                   <xsl:value-of select="$primary.significant"/>
 
 434                   <xsl:text>, </xsl:text>
 
 435                   <xsl:value-of select="$secondary"/>
 
 439             <xsl:if test="$refs[not(@significance) or @significance!='preferred'][not(see) and not(tertiary)]">
 
 440               <rx:index-item xsl:use-attribute-sets="xep.index.item.properties">
 
 441                 <xsl:attribute name="ref-key">
 
 442                   <xsl:value-of select="$primary"/>
 
 443                   <xsl:text>, </xsl:text>
 
 444                   <xsl:value-of select="$secondary"/>
 
 452         <xsl:variable name="page-number-citations">
 
 453           <xsl:for-each select="$refs[not(see) 
 
 455             <xsl:apply-templates select="." mode="reference">
 
 456               <xsl:with-param name="scope" select="$scope"/>
 
 457               <xsl:with-param name="role" select="$role"/>
 
 458               <xsl:with-param name="type" select="$type"/>
 
 459               <xsl:with-param name="position" select="position()"/>
 
 460             </xsl:apply-templates>
 
 465           <xsl:when test="$passivetex.extensions != '0'">
 
 466             <fotex:sort xmlns:fotex="http://www.tug.org/fotex">
 
 467               <xsl:copy-of select="$page-number-citations"/>
 
 471             <xsl:copy-of select="$page-number-citations"/>
 
 477     <xsl:if test="$refs[not(tertiary)]/*[self::see]">
 
 478       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[&scope;][1])]"
 
 480         <xsl:with-param name="scope" select="$scope"/>
 
 481         <xsl:with-param name="role" select="$role"/>
 
 482         <xsl:with-param name="type" select="$type"/>
 
 483         <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
 
 484       </xsl:apply-templates>
 
 489   <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::seealso]">
 
 490     <fo:block start-indent="2pc">
 
 491       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[&scope;][1])]"
 
 492                            mode="index-seealso">
 
 493           <xsl:with-param name="scope" select="$scope"/>
 
 494           <xsl:with-param name="role" select="$role"/>
 
 495           <xsl:with-param name="type" select="$type"/>
 
 496           <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
 
 497       </xsl:apply-templates>
 
 498       <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[&scope;][1]) = 1]" 
 
 499                            mode="index-tertiary">
 
 500           <xsl:with-param name="scope" select="$scope"/>
 
 501           <xsl:with-param name="role" select="$role"/>
 
 502           <xsl:with-param name="type" select="$type"/>
 
 503           <xsl:sort select="translate(&tertiary;, &lowercase;, &uppercase;)"/>
 
 504       </xsl:apply-templates>
 
 509 <xsl:template match="indexterm" mode="index-tertiary">
 
 510   <xsl:param name="scope" select="."/>
 
 511   <xsl:param name="role" select="''"/>
 
 512   <xsl:param name="type" select="''"/>
 
 513   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
 
 514   <xsl:variable name="refs" select="key('tertiary', $key)[&scope;]"/>
 
 516   <xsl:variable name="term.separator">
 
 517     <xsl:call-template name="index.separator">
 
 518       <xsl:with-param name="key" select="'index.term.separator'"/>
 
 522   <xsl:variable name="range.separator">
 
 523     <xsl:call-template name="index.separator">
 
 524       <xsl:with-param name="key" select="'index.range.separator'"/>
 
 528   <xsl:variable name="number.separator">
 
 529     <xsl:call-template name="index.separator">
 
 530       <xsl:with-param name="key" select="'index.number.separator'"/>
 
 535     <xsl:if test="$axf.extensions != 0">
 
 536       <xsl:attribute name="axf:suppress-duplicate-page-number">true</xsl:attribute>
 
 539     <xsl:for-each select="$refs/tertiary">
 
 540       <xsl:if test="@id or @xml:id">
 
 541         <fo:inline id="{(@id|@xml:id)[1]}"/>
 
 545     <xsl:value-of select="tertiary"/>
 
 548       <xsl:when test="$xep.extensions != 0">
 
 549         <xsl:if test="$refs[not(see)]">
 
 550           <xsl:copy-of select="$term.separator"/>
 
 551           <xsl:variable name="primary" select="&primary;"/>
 
 552           <xsl:variable name="secondary" select="&secondary;"/>
 
 553           <xsl:variable name="tertiary" select="&tertiary;"/>
 
 554           <xsl:variable name="primary.significant" select="concat(&primary;, $significant.flag)"/>
 
 555           <rx:page-index list-separator="{$number.separator}"
 
 556                          range-separator="{$range.separator}">
 
 557             <xsl:if test="$refs[@significance='preferred'][not(see)]">
 
 558               <rx:index-item xsl:use-attribute-sets="index.preferred.page.properties xep.index.item.properties">
 
 559                 <xsl:attribute name="ref-key">
 
 560                   <xsl:value-of select="$primary.significant"/>
 
 561                   <xsl:text>, </xsl:text>
 
 562                   <xsl:value-of select="$secondary"/>
 
 563                   <xsl:text>, </xsl:text>
 
 564                   <xsl:value-of select="$tertiary"/>
 
 568             <xsl:if test="$refs[not(@significance) or @significance!='preferred'][not(see)]">
 
 569               <rx:index-item xsl:use-attribute-sets="xep.index.item.properties">
 
 570                 <xsl:attribute name="ref-key">
 
 571                   <xsl:value-of select="$primary"/>
 
 572                   <xsl:text>, </xsl:text>
 
 573                   <xsl:value-of select="$secondary"/>
 
 574                   <xsl:text>, </xsl:text>
 
 575                   <xsl:value-of select="$tertiary"/>
 
 583         <xsl:variable name="page-number-citations">
 
 584           <xsl:for-each select="$refs[not(see)]">
 
 585             <xsl:apply-templates select="." mode="reference">
 
 586               <xsl:with-param name="scope" select="$scope"/>
 
 587               <xsl:with-param name="role" select="$role"/>
 
 588               <xsl:with-param name="type" select="$type"/>
 
 589               <xsl:with-param name="position" select="position()"/>
 
 590             </xsl:apply-templates>
 
 595           <xsl:when test="$passivetex.extensions != '0'">
 
 596             <fotex:sort xmlns:fotex="http://www.tug.org/fotex">
 
 597               <xsl:copy-of select="$page-number-citations"/>
 
 601             <xsl:copy-of select="$page-number-citations"/>
 
 607     <xsl:if test="$refs/see">
 
 608       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[&scope;][1])]"
 
 610         <xsl:with-param name="scope" select="$scope"/>
 
 611         <xsl:with-param name="role" select="$role"/>
 
 612         <xsl:with-param name="type" select="$type"/>
 
 613         <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
 
 614       </xsl:apply-templates>
 
 619   <xsl:if test="$refs/seealso">
 
 621       <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[&scope;][1])]"
 
 622                            mode="index-seealso">
 
 623         <xsl:with-param name="scope" select="$scope"/>
 
 624         <xsl:with-param name="role" select="$role"/>
 
 625         <xsl:with-param name="type" select="$type"/>
 
 626         <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
 
 627       </xsl:apply-templates>
 
 632 <xsl:template match="indexterm" mode="reference">
 
 633   <xsl:param name="scope" select="."/>
 
 634   <xsl:param name="role" select="''"/>
 
 635   <xsl:param name="type" select="''"/>
 
 636   <xsl:param name="position" select="0"/>
 
 637   <xsl:param name="separator" select="''"/>
 
 639   <xsl:variable name="term.separator">
 
 640     <xsl:call-template name="index.separator">
 
 641       <xsl:with-param name="key" select="'index.term.separator'"/>
 
 645   <xsl:variable name="range.separator">
 
 646     <xsl:call-template name="index.separator">
 
 647       <xsl:with-param name="key" select="'index.range.separator'"/>
 
 651   <xsl:variable name="number.separator">
 
 652     <xsl:call-template name="index.separator">
 
 653       <xsl:with-param name="key" select="'index.number.separator'"/>
 
 658     <xsl:when test="$separator != ''">
 
 659       <xsl:value-of select="$separator"/>
 
 661     <xsl:when test="$position = 1">
 
 662       <xsl:value-of select="$term.separator"/>
 
 665       <xsl:value-of select="$number.separator"/>
 
 670     <xsl:when test="@zone and string(@zone)">
 
 671       <xsl:call-template name="reference">
 
 672         <xsl:with-param name="zones" select="normalize-space(@zone)"/>
 
 673         <xsl:with-param name="scope" select="$scope"/>
 
 674         <xsl:with-param name="role" select="$role"/>
 
 675         <xsl:with-param name="type" select="$type"/>
 
 678     <xsl:when test="ancestor::*[contains(local-name(),'info') and not(starts-with(local-name(),'info'))]">
 
 679       <xsl:call-template name="info.reference">
 
 680         <xsl:with-param name="scope" select="$scope"/>
 
 681         <xsl:with-param name="role" select="$role"/>
 
 682         <xsl:with-param name="type" select="$type"/>
 
 686       <xsl:variable name="id">
 
 687         <xsl:call-template name="object.id"/>
 
 690       <fo:basic-link internal-destination="{$id}"
 
 691                      xsl:use-attribute-sets="index.page.number.properties">
 
 692         <fo:page-number-citation ref-id="{$id}"/>
 
 695       <xsl:if test="key('endofrange', $id)[&scope;]">
 
 696         <xsl:apply-templates select="key('endofrange', $id)[&scope;][last()]"
 
 698           <xsl:with-param name="scope" select="$scope"/>
 
 699           <xsl:with-param name="role" select="$role"/>
 
 700           <xsl:with-param name="type" select="$type"/>
 
 701           <xsl:with-param name="separator" select="$range.separator"/>
 
 702         </xsl:apply-templates>
 
 708 <xsl:template name="reference">
 
 709   <xsl:param name="scope" select="."/>
 
 710   <xsl:param name="role" select="''"/>
 
 711   <xsl:param name="type" select="''"/>
 
 712   <xsl:param name="zones"/>
 
 714   <xsl:variable name="number.separator">
 
 715     <xsl:call-template name="index.separator">
 
 716       <xsl:with-param name="key" select="'index.number.separator'"/>
 
 721     <xsl:when test="contains($zones, ' ')">
 
 722       <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
 
 723       <xsl:variable name="target" select="key('id', $zone)"/>
 
 725       <xsl:variable name="id">
 
 726         <xsl:call-template name="object.id">
 
 727            <xsl:with-param name="object" select="$target[1]"/>
 
 731       <fo:basic-link internal-destination="{$id}"
 
 732                      xsl:use-attribute-sets="index.page.number.properties">
 
 733         <fo:page-number-citation ref-id="{$id}"/>
 
 736       <xsl:if test="$passivetex.extensions = '0'">
 
 737         <xsl:copy-of select="$number.separator"/>
 
 739       <xsl:call-template name="reference">
 
 740         <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
 
 741         <xsl:with-param name="scope" select="$scope"/>
 
 742         <xsl:with-param name="role" select="$role"/>
 
 743         <xsl:with-param name="type" select="$type"/>
 
 747       <xsl:variable name="zone" select="$zones"/>
 
 748       <xsl:variable name="target" select="key('id', $zone)"/>
 
 750       <xsl:variable name="id">
 
 751         <xsl:call-template name="object.id">
 
 752           <xsl:with-param name="object" select="$target[1]"/>
 
 756       <fo:basic-link internal-destination="{$id}"
 
 757                      xsl:use-attribute-sets="index.page.number.properties">
 
 758         <fo:page-number-citation ref-id="{$id}"/>
 
 764 <xsl:template name="info.reference">
 
 765   <!-- This is not perfect. It doesn't treat indexterm inside info element as a range covering whole parent of info.
 
 766        It also not work when there is no ID generated for parent element. But it works in the most common cases. -->
 
 767   <xsl:param name="scope" select="."/>
 
 768   <xsl:param name="role" select="''"/>
 
 769   <xsl:param name="type" select="''"/>
 
 771   <xsl:variable name="target" select="(ancestor::appendix|ancestor::article|ancestor::bibliography|ancestor::book|
 
 772                                        ancestor::chapter|ancestor::glossary|ancestor::part|ancestor::preface|
 
 773                                        ancestor::refentry|ancestor::reference|ancestor::refsect1|ancestor::refsect2|
 
 774                                        ancestor::refsect3|ancestor::refsection|ancestor::refsynopsisdiv|
 
 775                                        ancestor::sect1|ancestor::sect2|ancestor::sect3|ancestor::sect4|ancestor::sect5|
 
 776                                        ancestor::section|ancestor::setindex|ancestor::set|ancestor::sidebar|ancestor::mediaobject)[&scope;]"/>
 
 778   <xsl:variable name="id">
 
 779     <xsl:call-template name="object.id">
 
 780       <xsl:with-param name="object" select="$target[position() = last()]"/>
 
 784   <fo:basic-link internal-destination="{$id}"
 
 785                  xsl:use-attribute-sets="index.page.number.properties">
 
 786     <fo:page-number-citation ref-id="{$id}"/>
 
 790 <xsl:template match="indexterm" mode="index-see">
 
 791    <xsl:param name="scope" select="."/>
 
 792   <xsl:param name="role" select="''"/>
 
 793   <xsl:param name="type" select="''"/>
 
 796      <xsl:text> (</xsl:text>
 
 797      <xsl:call-template name="gentext">
 
 798        <xsl:with-param name="key" select="'see'"/>
 
 800      <xsl:text> </xsl:text>
 
 801      <xsl:value-of select="see"/>
 
 802      <xsl:text>)</xsl:text>
 
 806 <xsl:template match="indexterm" mode="index-seealso">
 
 807    <xsl:param name="scope" select="."/>
 
 808   <xsl:param name="role" select="''"/>
 
 809   <xsl:param name="type" select="''"/>
 
 811   <xsl:for-each select="seealso">
 
 812     <xsl:sort select="translate(., &lowercase;, &uppercase;)"/>
 
 814       <xsl:text>(</xsl:text>
 
 815       <xsl:call-template name="gentext">
 
 816         <xsl:with-param name="key" select="'seealso'"/>
 
 818       <xsl:text> </xsl:text>
 
 819       <xsl:value-of select="."/>
 
 820       <xsl:text>)</xsl:text>
 
 826 <!-- ====================================================================== -->
 
 828 <xsl:template name="generate-index-markup">
 
 829   <xsl:param name="scope" select="(ancestor::book|/)[last()]"/>
 
 830   <xsl:param name="role" select="@role"/>
 
 831   <xsl:param name="type" select="@type"/>
 
 833   <xsl:variable name="terms" select="$scope//indexterm[count(.|key('letter',
 
 834                                      translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[&scope;][1]) = 1]"/>
 
 835   <xsl:variable name="alphabetical"
 
 836                 select="$terms[contains(concat(&lowercase;, &uppercase;),
 
 837                                         substring(&primary;, 1, 1))]"/>
 
 838   <xsl:variable name="others" select="$terms[not(contains(concat(&lowercase;,
 
 840                                              substring(&primary;, 1, 1)))]"/>
 
 842   <xsl:text><index>
</xsl:text>
 
 843   <xsl:if test="$others">
 
 844     <xsl:text>
<indexdiv>
</xsl:text>
 
 845     <xsl:text><title></xsl:text>
 
 846     <xsl:call-template name="gentext">
 
 847       <xsl:with-param name="key" select="'index symbols'"/>
 
 849     <xsl:text></title>
</xsl:text>
 
 850     <xsl:apply-templates select="$others[count(.|key('primary',
 
 851                                  &primary;)[&scope;][1]) = 1]"
 
 852                          mode="index-symbol-div-markup">
 
 853       <xsl:with-param name="scope" select="$scope"/>
 
 854       <xsl:with-param name="role" select="$role"/>
 
 855       <xsl:with-param name="type" select="$type"/>
 
 856       <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 857     </xsl:apply-templates>
 
 858     <xsl:text></indexdiv>
</xsl:text>
 
 861   <xsl:apply-templates select="$alphabetical[count(.|key('letter',
 
 862                                translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[&scope;][1]) = 1]"
 
 863                        mode="index-div-markup">
 
 864       <xsl:with-param name="scope" select="$scope"/>
 
 865       <xsl:with-param name="role" select="$role"/>
 
 866       <xsl:with-param name="type" select="$type"/>
 
 867       <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 868   </xsl:apply-templates>
 
 869   <xsl:text></index>
</xsl:text>
 
 872 <xsl:template match="*" mode="index-markup">
 
 873   <xsl:param name="scope" select="."/>
 
 874   <xsl:param name="role" select="''"/>
 
 875   <xsl:param name="type" select="''"/>
 
 877   <xsl:text><</xsl:text>
 
 878   <xsl:value-of select="local-name(.)"/>
 
 879   <xsl:text>>
</xsl:text>
 
 880   <xsl:apply-templates mode="index-markup">
 
 881     <xsl:with-param name="scope" select="$scope"/>
 
 882     <xsl:with-param name="role" select="$role"/>
 
 883     <xsl:with-param name="type" select="$type"/>
 
 884   </xsl:apply-templates>
 
 887 <xsl:template match="indexterm" mode="index-div-markup">
 
 888   <xsl:param name="scope" select="."/>
 
 889   <xsl:param name="role" select="''"/>
 
 890   <xsl:param name="type" select="''"/>
 
 891   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
 
 892   <xsl:text>
<indexdiv>
</xsl:text>
 
 893   <xsl:text><title></xsl:text>
 
 894   <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
 
 895   <xsl:text></title>
</xsl:text>
 
 897   <xsl:apply-templates select="key('letter', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]"
 
 898                        mode="index-primary-markup">
 
 899     <xsl:with-param name="scope" select="$scope"/>
 
 900     <xsl:with-param name="role" select="$role"/>
 
 901     <xsl:with-param name="type" select="$type"/>
 
 902     <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 903   </xsl:apply-templates>
 
 904   <xsl:text></indexdiv>
</xsl:text>
 
 907 <xsl:template match="indexterm" mode="index-symbol-div-markup">
 
 908   <xsl:param name="scope" select="."/>
 
 909   <xsl:param name="role" select="''"/>
 
 910   <xsl:param name="type" select="''"/>
 
 911   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
 
 913   <xsl:apply-templates select="key('letter', $key)[&scope;][count(.|key('primary', &primary;)[&scope;][1]) = 1]"
 
 914                        mode="index-primary-markup">
 
 915     <xsl:with-param name="scope" select="$scope"/>
 
 916     <xsl:with-param name="role" select="$role"/>
 
 917     <xsl:with-param name="type" select="$type"/>
 
 918     <xsl:sort select="translate(&primary;, &lowercase;, &uppercase;)"/>
 
 919   </xsl:apply-templates>
 
 922 <xsl:template match="indexterm" mode="index-primary-markup">
 
 923   <xsl:param name="scope" select="."/>
 
 924   <xsl:param name="role" select="''"/>
 
 925   <xsl:param name="type" select="''"/>
 
 926   <xsl:variable name="key" select="&primary;"/>
 
 927   <xsl:variable name="refs" select="key('primary', $key)[&scope;]"/>
 
 928   <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
 
 930   <xsl:text>
<indexentry>
</xsl:text>
 
 931   <xsl:text><primaryie></xsl:text>
 
 932   <xsl:text><phrase></xsl:text>
 
 933   <xsl:call-template name="escape-text">
 
 934     <xsl:with-param name="text" select="string(primary)"/>
 
 936   <xsl:text></phrase></xsl:text>
 
 937   <xsl:if test="$pages">,</xsl:if>
 
 938   <xsl:text>
</xsl:text>
 
 940   <xsl:for-each select="$pages">
 
 941     <xsl:apply-templates select="." mode="reference-markup">
 
 942       <xsl:with-param name="scope" select="$scope"/>
 
 943       <xsl:with-param name="role" select="$role"/>
 
 944       <xsl:with-param name="type" select="$type"/>
 
 945     </xsl:apply-templates>
 
 948   <xsl:text></primaryie>
</xsl:text>
 
 950   <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::see or self::seealso]">
 
 951     <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[&scope;][1])]"
 
 952                          mode="index-see-markup">
 
 953       <xsl:with-param name="scope" select="$scope"/>
 
 954       <xsl:with-param name="role" select="$role"/>
 
 955       <xsl:with-param name="type" select="$type"/>
 
 956       <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
 
 957     </xsl:apply-templates>
 
 959     <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[&scope;][1])]"
 
 960                          mode="index-seealso-markup">
 
 961       <xsl:with-param name="scope" select="$scope"/>
 
 962       <xsl:with-param name="role" select="$role"/>
 
 963       <xsl:with-param name="type" select="$type"/>
 
 964       <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
 
 965     </xsl:apply-templates>
 
 967     <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[&scope;][1]) = 1]" 
 
 968                          mode="index-secondary-markup">
 
 969       <xsl:with-param name="scope" select="$scope"/>
 
 970       <xsl:with-param name="role" select="$role"/>
 
 971       <xsl:with-param name="type" select="$type"/>
 
 972       <xsl:sort select="translate(&secondary;, &lowercase;, &uppercase;)"/>
 
 973     </xsl:apply-templates>
 
 975   <xsl:text></indexentry>
</xsl:text>
 
 978 <xsl:template match="indexterm" mode="index-secondary-markup">
 
 979   <xsl:param name="scope" select="."/>
 
 980   <xsl:param name="role" select="''"/>
 
 981   <xsl:param name="type" select="''"/>
 
 982   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
 
 983   <xsl:variable name="refs" select="key('secondary', $key)[&scope;]"/>
 
 984   <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
 
 986   <xsl:text><secondaryie></xsl:text>
 
 987   <xsl:text><phrase></xsl:text>
 
 988   <xsl:call-template name="escape-text">
 
 989     <xsl:with-param name="text" select="string(secondary)"/>
 
 991   <xsl:text></phrase></xsl:text>
 
 992   <xsl:if test="$pages">,</xsl:if>
 
 993   <xsl:text>
</xsl:text>
 
 995   <xsl:for-each select="$pages">
 
 996     <xsl:apply-templates select="." mode="reference-markup">
 
 997       <xsl:with-param name="scope" select="$scope"/>
 
 998       <xsl:with-param name="role" select="$role"/>
 
 999       <xsl:with-param name="type" select="$type"/>
 
1000     </xsl:apply-templates>
 
1003   <xsl:text></secondaryie>
</xsl:text>
 
1005   <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::see or self::seealso]">
 
1006     <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[&scope;][1])]"
 
1007                          mode="index-see-markup">
 
1008       <xsl:with-param name="scope" select="$scope"/>
 
1009       <xsl:with-param name="role" select="$role"/>
 
1010       <xsl:with-param name="type" select="$type"/>
 
1011       <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
 
1012     </xsl:apply-templates>
 
1013     <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[&scope;][1])]"
 
1014                          mode="index-seealso-markup">
 
1015       <xsl:with-param name="scope" select="$scope"/>
 
1016       <xsl:with-param name="role" select="$role"/>
 
1017       <xsl:with-param name="type" select="$type"/>
 
1018       <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
 
1019     </xsl:apply-templates>
 
1020     <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[&scope;][1]) = 1]" 
 
1021                          mode="index-tertiary-markup">
 
1022       <xsl:with-param name="scope" select="$scope"/>
 
1023       <xsl:with-param name="role" select="$role"/>
 
1024       <xsl:with-param name="type" select="$type"/>
 
1025       <xsl:sort select="translate(&tertiary;, &lowercase;, &uppercase;)"/>
 
1026     </xsl:apply-templates>
 
1030 <xsl:template match="indexterm" mode="index-tertiary-markup">
 
1031   <xsl:param name="scope" select="."/>
 
1032   <xsl:param name="role" select="''"/>
 
1033   <xsl:param name="type" select="''"/>
 
1034   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
 
1035   <xsl:variable name="refs" select="key('tertiary', $key)[&scope;]"/>
 
1036   <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
 
1038   <xsl:text><tertiaryie></xsl:text>
 
1039   <xsl:text><phrase></xsl:text>
 
1040   <xsl:call-template name="escape-text">
 
1041     <xsl:with-param name="text" select="string(tertiary)"/>
 
1042   </xsl:call-template>
 
1043   <xsl:text></phrase></xsl:text>
 
1044   <xsl:if test="$pages">,</xsl:if>
 
1045   <xsl:text>
</xsl:text>
 
1047   <xsl:for-each select="$pages">
 
1048     <xsl:apply-templates select="." mode="reference-markup">
 
1049       <xsl:with-param name="scope" select="$scope"/>
 
1050       <xsl:with-param name="role" select="$role"/>
 
1051       <xsl:with-param name="type" select="$type"/>
 
1052     </xsl:apply-templates>
 
1055   <xsl:text></tertiaryie>
</xsl:text>
 
1057   <xsl:variable name="see" select="$refs/see | $refs/seealso"/>
 
1058   <xsl:if test="$see">
 
1059     <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[&scope;][1])]"
 
1060                          mode="index-see-markup">
 
1061       <xsl:with-param name="scope" select="$scope"/>
 
1062       <xsl:with-param name="role" select="$role"/>
 
1063       <xsl:with-param name="type" select="$type"/>
 
1064       <xsl:sort select="translate(see, &lowercase;, &uppercase;)"/>
 
1065     </xsl:apply-templates>
 
1066     <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[&scope;][1])]"
 
1067                          mode="index-seealso-markup">
 
1068       <xsl:with-param name="scope" select="$scope"/>
 
1069       <xsl:with-param name="role" select="$role"/>
 
1070       <xsl:with-param name="type" select="$type"/>
 
1071       <xsl:sort select="translate(seealso, &lowercase;, &uppercase;)"/>
 
1072     </xsl:apply-templates>
 
1076 <xsl:template match="indexterm" mode="reference-markup">
 
1077   <xsl:param name="scope" select="."/>
 
1078   <xsl:param name="role" select="''"/>
 
1079   <xsl:param name="type" select="''"/>
 
1082     <xsl:when test="@zone and string(@zone)">
 
1083       <xsl:call-template name="reference-markup">
 
1084         <xsl:with-param name="zones" select="normalize-space(@zone)"/>
 
1085         <xsl:with-param name="scope" select="$scope"/>
 
1086         <xsl:with-param name="role" select="$role"/>
 
1087         <xsl:with-param name="type" select="$type"/>
 
1088       </xsl:call-template>
 
1091       <xsl:variable name="id">
 
1092         <xsl:call-template name="object.id"/>
 
1097         <xsl:when test="@startref and @class='endofrange'">
 
1098           <xsl:text><phrase role="pageno"></xsl:text>
 
1099           <xsl:text><link linkend="</xsl:text>
 
1100           <xsl:value-of select="@startref"/>
 
1101           <xsl:text>"></xsl:text>
 
1102           <fo:basic-link internal-destination="{@startref}"
 
1103                      xsl:use-attribute-sets="index.page.number.properties">
 
1104             <fo:page-number-citation ref-id="{@startref}"/>
 
1105             <xsl:text>-</xsl:text>
 
1106             <fo:page-number-citation ref-id="{$id}"/>
 
1108           <xsl:text></link></xsl:text>
 
1109           <xsl:text></phrase>
</xsl:text>
 
1112           <xsl:text><phrase role="pageno"></xsl:text>
 
1114             <xsl:text><link linkend="</xsl:text>
 
1115             <xsl:value-of select="$id"/>
 
1116             <xsl:text>"></xsl:text>
 
1118           <fo:basic-link internal-destination="{$id}"
 
1119                      xsl:use-attribute-sets="index.page.number.properties">
 
1120             <fo:page-number-citation ref-id="{$id}"/>
 
1123             <xsl:text></link></xsl:text>
 
1125           <xsl:text></phrase>
</xsl:text>
 
1132 <xsl:template name="reference-markup">
 
1133   <xsl:param name="scope" select="."/>
 
1134   <xsl:param name="role" select="''"/>
 
1135   <xsl:param name="type" select="''"/>
 
1136   <xsl:param name="zones"/>
 
1138     <xsl:when test="contains($zones, ' ')">
 
1139       <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
 
1140       <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
 
1142       <xsl:variable name="id">
 
1143         <xsl:call-template name="object.id">
 
1144           <xsl:with-param name="object" select="$target[1]"/>
 
1145         </xsl:call-template>
 
1148       <xsl:text><phrase fole="pageno"></xsl:text>
 
1149       <xsl:if test="$target[1]/@id or $target[1]/@xml:id">
 
1150         <xsl:text><link linkend="</xsl:text>
 
1151         <xsl:value-of select="$id"/>
 
1152         <xsl:text>"></xsl:text>
 
1154       <fo:basic-link internal-destination="{$id}"
 
1155                      xsl:use-attribute-sets="index.page.number.properties">
 
1156         <fo:page-number-citation ref-id="{$id}"/>
 
1158       <xsl:if test="$target[1]/@id or $target[1]/@xml:id">
 
1159         <xsl:text></link></xsl:text>
 
1161       <xsl:text></phrase>
</xsl:text>
 
1163       <xsl:call-template name="reference">
 
1164         <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
 
1165         <xsl:with-param name="scope" select="$scope"/>
 
1166         <xsl:with-param name="role" select="$role"/>
 
1167         <xsl:with-param name="type" select="$type"/>
 
1168       </xsl:call-template>
 
1171       <xsl:variable name="zone" select="$zones"/>
 
1172       <xsl:variable name="target" select="key('id', $zone)[&scope;]"/>
 
1174       <xsl:variable name="id">
 
1175         <xsl:call-template name="object.id">
 
1176           <xsl:with-param name="object" select="$target[1]"/>
 
1177         </xsl:call-template>
 
1180       <xsl:text><phrase role="pageno"></xsl:text>
 
1181       <xsl:if test="$target[1]/@id or target[1]/@xml:id">
 
1182         <xsl:text><link linkend="</xsl:text>
 
1183         <xsl:value-of select="$id"/>
 
1184         <xsl:text>"></xsl:text>
 
1186       <fo:basic-link internal-destination="{$id}"
 
1187                      xsl:use-attribute-sets="index.page.number.properties">
 
1188         <fo:page-number-citation ref-id="{$id}"/>
 
1190       <xsl:if test="$target[1]/@id or target[1]/@xml:id">
 
1191         <xsl:text></link></xsl:text>
 
1193       <xsl:text></phrase>
</xsl:text>
 
1198 <xsl:template match="indexterm" mode="index-see-markup">
 
1199   <xsl:param name="scope" select="."/>
 
1200   <xsl:param name="role" select="''"/>
 
1201   <xsl:param name="type" select="''"/>
 
1203     <xsl:text><seeie></xsl:text>
 
1204     <xsl:text><phrase></xsl:text>
 
1205     <xsl:call-template name="escape-text">
 
1206       <xsl:with-param name="text" select="string(see)"/>
 
1207     </xsl:call-template>
 
1208     <xsl:text></phrase></xsl:text>
 
1209     <xsl:text></seeie>
</xsl:text>
 
1213 <xsl:template match="indexterm" mode="index-seealso-markup">
 
1214   <xsl:param name="scope" select="."/>
 
1215   <xsl:param name="role" select="''"/>
 
1216   <xsl:param name="type" select="''"/>
 
1218     <xsl:text><seealsoie></xsl:text>
 
1219     <xsl:text><phrase></xsl:text>
 
1220     <xsl:call-template name="escape-text">
 
1221       <xsl:with-param name="text" select="string(seealso)"/>
 
1222     </xsl:call-template>
 
1223     <xsl:text></phrase></xsl:text>
 
1224     <xsl:text></seealsoie>
</xsl:text>
 
1228 <xsl:template name="escape-text">
 
1229   <xsl:param name="text" select="''"/>
 
1231   <xsl:variable name="ltpos" select="substring-before($text, '<')"/>
 
1232   <xsl:variable name="amppos" select="substring-before($text, '&')"/>
 
1235     <xsl:when test="contains($text,'<') and contains($text, '&')
 
1236                     and string-length($ltpos) < string-length($amppos)">
 
1237       <xsl:value-of select="$ltpos"/>
 
1238       <xsl:text>&lt;</xsl:text>
 
1239       <xsl:call-template name="escape-text">
 
1240         <xsl:with-param name="text" select="substring-after($text, '<')"/>
 
1241       </xsl:call-template>
 
1244     <xsl:when test="contains($text,'<') and contains($text, '&')
 
1245                     and string-length($amppos) < string-length($ltpos)">
 
1246       <xsl:value-of select="$amppos"/>
 
1247       <xsl:text>&amp;</xsl:text>
 
1248       <xsl:call-template name="escape-text">
 
1249         <xsl:with-param name="text" select="substring-after($text, '&')"/>
 
1250       </xsl:call-template>
 
1253     <xsl:when test="contains($text, '<')">
 
1254       <xsl:value-of select="$ltpos"/>
 
1255       <xsl:text>&lt;</xsl:text>
 
1256       <xsl:call-template name="escape-text">
 
1257         <xsl:with-param name="text" select="substring-after($text, '<')"/>
 
1258       </xsl:call-template>
 
1261     <xsl:when test="contains($text, '&')">
 
1262       <xsl:value-of select="$amppos"/>
 
1263       <xsl:text>&amp;</xsl:text>
 
1264       <xsl:call-template name="escape-text">
 
1265         <xsl:with-param name="text" select="substring-after($text, '&')"/>
 
1266       </xsl:call-template>
 
1270       <xsl:value-of select="$text"/>
 
1275 <xsl:template name="index.separator">
 
1276   <xsl:param name="key" select="''"/>
 
1277   <xsl:param name="lang">
 
1278     <xsl:call-template name="l10n.language"/>
 
1282     <xsl:when test="$key = 'index.term.separator'">
 
1284         <!-- Use the override if not blank -->
 
1285         <xsl:when test="$index.term.separator != ''">
 
1286           <xsl:copy-of select="$index.term.separator"/>
 
1289           <xsl:call-template name="gentext.template">
 
1290             <xsl:with-param name="lang" select="$lang"/>
 
1291             <xsl:with-param name="context">index</xsl:with-param>
 
1292             <xsl:with-param name="name">term-separator</xsl:with-param>
 
1293           </xsl:call-template>
 
1297     <xsl:when test="$key = 'index.number.separator'">
 
1299         <!-- Use the override if not blank -->
 
1300         <xsl:when test="$index.number.separator != ''">
 
1301           <xsl:copy-of select="$index.number.separator"/>
 
1304           <xsl:call-template name="gentext.template">
 
1305             <xsl:with-param name="lang" select="$lang"/>
 
1306             <xsl:with-param name="context">index</xsl:with-param>
 
1307             <xsl:with-param name="name">number-separator</xsl:with-param>
 
1308           </xsl:call-template>
 
1312     <xsl:when test="$key = 'index.range.separator'">
 
1314         <!-- Use the override if not blank -->
 
1315         <xsl:when test="$index.range.separator != ''">
 
1316           <xsl:copy-of select="$index.range.separator"/>
 
1319           <xsl:call-template name="gentext.template">
 
1320             <xsl:with-param name="lang" select="$lang"/>
 
1321             <xsl:with-param name="context">index</xsl:with-param>
 
1322             <xsl:with-param name="name">range-separator</xsl:with-param>
 
1323           </xsl:call-template>