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"
 
  11 <!-- ********************************************************************
 
  12      $Id: index.xsl 8724 2010-07-15 07:53:27Z kosek $
 
  13      ********************************************************************
 
  15      This file is part of the XSL DocBook Stylesheet distribution.
 
  16      See ../README or http://docbook.sf.net/release/xsl/current/ for
 
  17      copyright and other information.
 
  19      ******************************************************************** -->
 
  21 <!-- ==================================================================== -->
 
  23 <xsl:template match="index">
 
  24   <xsl:variable name="id">
 
  25     <xsl:call-template name="object.id"/>
 
  28  <xsl:if test="$generate.index != 0">
 
  30     <xsl:when test="$make.index.markup != 0">
 
  32         <xsl:call-template name="generate-index-markup">
 
  33           <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
 
  39         <xsl:call-template name="index.titlepage"/>
 
  41       <xsl:apply-templates/>
 
  42       <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
 
  43         <xsl:call-template name="generate-index">
 
  44           <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
 
  52 <xsl:template match="book/index|part/index">
 
  53   <xsl:variable name="id">
 
  54     <xsl:call-template name="object.id"/>
 
  57  <xsl:if test="$generate.index != 0">
 
  58   <xsl:variable name="master-reference">
 
  59     <xsl:call-template name="select.pagemaster">
 
  60       <xsl:with-param name="pageclass">
 
  61         <xsl:if test="$make.index.markup != 0">body</xsl:if>
 
  66   <fo:page-sequence hyphenate="{$hyphenate}"
 
  67                     master-reference="{$master-reference}">
 
  68     <xsl:attribute name="language">
 
  69       <xsl:call-template name="l10n.language"/>
 
  71     <xsl:attribute name="format">
 
  72       <xsl:call-template name="page.number.format">
 
  73         <xsl:with-param name="master-reference" select="$master-reference"/>
 
  77     <xsl:attribute name="initial-page-number">
 
  78       <xsl:call-template name="initial.page.number">
 
  79         <xsl:with-param name="master-reference" select="$master-reference"/>
 
  83     <xsl:attribute name="force-page-count">
 
  84       <xsl:call-template name="force.page.count">
 
  85         <xsl:with-param name="master-reference" select="$master-reference"/>
 
  89     <xsl:attribute name="hyphenation-character">
 
  90       <xsl:call-template name="gentext">
 
  91         <xsl:with-param name="key" select="'hyphenation-character'"/>
 
  94     <xsl:attribute name="hyphenation-push-character-count">
 
  95       <xsl:call-template name="gentext">
 
  96         <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
 
  99     <xsl:attribute name="hyphenation-remain-character-count">
 
 100       <xsl:call-template name="gentext">
 
 101         <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
 
 105     <xsl:apply-templates select="." mode="running.head.mode">
 
 106       <xsl:with-param name="master-reference" select="$master-reference"/>
 
 107     </xsl:apply-templates>
 
 108     <xsl:apply-templates select="." mode="running.foot.mode">
 
 109       <xsl:with-param name="master-reference" select="$master-reference"/>
 
 110     </xsl:apply-templates>
 
 112     <fo:flow flow-name="xsl-region-body">
 
 113       <xsl:call-template name="set.flow.properties">
 
 114         <xsl:with-param name="element" select="local-name(.)"/>
 
 115         <xsl:with-param name="master-reference" select="$master-reference"/>
 
 119                 xsl:use-attribute-sets="component.titlepage.properties">
 
 120         <xsl:call-template name="index.titlepage"/>
 
 122       <xsl:apply-templates/>
 
 123       <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
 
 126           <xsl:when test="$make.index.markup != 0">
 
 127             <fo:block wrap-option='no-wrap'
 
 128                       white-space-collapse='false'
 
 129                       xsl:use-attribute-sets="monospace.verbatim.properties"
 
 130                       linefeed-treatment="preserve">
 
 131               <xsl:call-template name="generate-index-markup">
 
 132                 <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
 
 136           <xsl:when test="indexentry|indexdiv/indexentry">
 
 137             <xsl:apply-templates/>
 
 140             <xsl:call-template name="generate-index">
 
 141               <xsl:with-param name="scope" select="(ancestor::book|/)[last()]"/>
 
 151 <xsl:template match="setindex">
 
 152   <xsl:variable name="id">
 
 153     <xsl:call-template name="object.id"/>
 
 156  <xsl:if test="$generate.index != 0">
 
 157   <xsl:variable name="master-reference">
 
 158     <xsl:call-template name="select.pagemaster">
 
 159       <xsl:with-param name="pageclass">
 
 161           <xsl:when test="$make.index.markup != 0">body</xsl:when>
 
 162           <xsl:otherwise>index</xsl:otherwise>
 
 168   <fo:page-sequence hyphenate="{$hyphenate}"
 
 169                     master-reference="{$master-reference}">
 
 170     <xsl:attribute name="language">
 
 171       <xsl:call-template name="l10n.language"/>
 
 173     <xsl:attribute name="format">
 
 174       <xsl:call-template name="page.number.format">
 
 175         <xsl:with-param name="master-reference" select="$master-reference"/>
 
 179     <xsl:attribute name="initial-page-number">
 
 180       <xsl:call-template name="initial.page.number">
 
 181         <xsl:with-param name="master-reference" select="$master-reference"/>
 
 185     <xsl:attribute name="force-page-count">
 
 186       <xsl:call-template name="force.page.count">
 
 187         <xsl:with-param name="master-reference" select="$master-reference"/>
 
 191     <xsl:attribute name="hyphenation-character">
 
 192       <xsl:call-template name="gentext">
 
 193         <xsl:with-param name="key" select="'hyphenation-character'"/>
 
 196     <xsl:attribute name="hyphenation-push-character-count">
 
 197       <xsl:call-template name="gentext">
 
 198         <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
 
 201     <xsl:attribute name="hyphenation-remain-character-count">
 
 202       <xsl:call-template name="gentext">
 
 203         <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
 
 207     <xsl:apply-templates select="." mode="running.head.mode">
 
 208       <xsl:with-param name="master-reference" select="$master-reference"/>
 
 209     </xsl:apply-templates>
 
 210     <xsl:apply-templates select="." mode="running.foot.mode">
 
 211       <xsl:with-param name="master-reference" select="$master-reference"/>
 
 212     </xsl:apply-templates>
 
 214     <fo:flow flow-name="xsl-region-body">
 
 215       <xsl:call-template name="set.flow.properties">
 
 216         <xsl:with-param name="element" select="local-name(.)"/>
 
 217         <xsl:with-param name="master-reference" select="$master-reference"/>
 
 220       <fo:block id="{$id}">
 
 221         <xsl:call-template name="setindex.titlepage"/>
 
 223       <xsl:apply-templates/>
 
 224       <xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
 
 227           <xsl:when test="$make.index.markup != 0">
 
 228             <fo:block wrap-option='no-wrap'
 
 229                       white-space-collapse='false'
 
 230                       xsl:use-attribute-sets="monospace.verbatim.properties"
 
 231                       linefeed-treatment="preserve">
 
 232               <xsl:call-template name="generate-index-markup">
 
 233                 <xsl:with-param name="scope" select="/"/>
 
 237           <xsl:when test="indexentry|indexdiv/indexentry">
 
 238             <xsl:apply-templates/>
 
 241             <xsl:call-template name="generate-index">
 
 242               <xsl:with-param name="scope" select="/"/>
 
 252 <xsl:template match="index/indexinfo"></xsl:template>
 
 253 <xsl:template match="index/info"></xsl:template>
 
 254 <xsl:template match="index/title"></xsl:template>
 
 255 <xsl:template match="index/subtitle"></xsl:template>
 
 256 <xsl:template match="index/titleabbrev"></xsl:template>
 
 258 <!-- ==================================================================== -->
 
 260 <xsl:template name="indexdiv.title">
 
 261   <xsl:param name="title"/>
 
 262   <xsl:param name="titlecontent"/>
 
 264   <fo:block xsl:use-attribute-sets="index.div.title.properties">
 
 266       <xsl:when test="$title">
 
 267         <xsl:apply-templates select="." mode="object.title.markup">
 
 268           <xsl:with-param name="allow-anchors" select="1"/>
 
 269         </xsl:apply-templates>
 
 272         <xsl:copy-of select="$titlecontent"/>
 
 278 <xsl:template match="indexdiv">
 
 280     <xsl:call-template name="indexdiv.titlepage"/>
 
 281     <xsl:apply-templates/>
 
 285 <xsl:template match="indexdiv/title"/>
 
 286 <xsl:template match="indexdiv/subtitle"/>
 
 287 <xsl:template match="indexdiv/titleabbrev"/>
 
 289 <!-- ==================================================================== -->
 
 291 <!-- Text used for distiguishing between normal and significant entries -->
 
 292 <xsl:variable name="significant.flag">.tnacifingis</xsl:variable>
 
 294 <xsl:template match="indexterm" name="indexterm">
 
 295   <!-- Temporal workaround for bug in AXF -->
 
 296   <xsl:variable name="wrapper.name">
 
 298       <xsl:when test="$axf.extensions != 0 or $fop1.extensions != 0">
 
 299         <xsl:call-template name="inline.or.block"/>
 
 301       <xsl:otherwise>fo:wrapper</xsl:otherwise>
 
 305   <xsl:element name="{$wrapper.name}">
 
 306     <xsl:attribute name="id">
 
 307       <xsl:call-template name="object.id"/>
 
 310       <xsl:when test="$xep.extensions != 0">
 
 311         <xsl:attribute name="rx:key">
 
 312           <xsl:value-of select="&primary;"/>
 
 313           <xsl:if test="@significance='preferred'"><xsl:value-of select="$significant.flag"/></xsl:if>
 
 314           <xsl:if test="secondary">
 
 315             <xsl:text>, </xsl:text>
 
 316             <xsl:value-of select="&secondary;"/>
 
 318           <xsl:if test="tertiary">
 
 319             <xsl:text>, </xsl:text>
 
 320             <xsl:value-of select="&tertiary;"/>
 
 326           <xsl:call-template name="comment-escape-string">
 
 327             <xsl:with-param name="string">
 
 328               <xsl:value-of select="primary"/>
 
 329               <xsl:if test="secondary">
 
 330                 <xsl:text>, </xsl:text>
 
 331                 <xsl:value-of select="secondary"/>
 
 333               <xsl:if test="tertiary">
 
 334                 <xsl:text>, </xsl:text>
 
 335                 <xsl:value-of select="tertiary"/>
 
 345 <xsl:template match="indexterm[@class='startofrange']">
 
 347     <xsl:when test="$xep.extensions != 0">
 
 348       <rx:begin-index-range>
 
 349         <xsl:call-template name="anchor"/>
 
 350         <xsl:attribute name="rx:key">
 
 351           <xsl:value-of select="&primary;"/>
 
 352           <xsl:if test="@significance='preferred'"><xsl:value-of select="$significant.flag"/></xsl:if>
 
 353           <xsl:if test="secondary">
 
 354             <xsl:text>, </xsl:text>
 
 355             <xsl:value-of select="&secondary;"/>
 
 357           <xsl:if test="tertiary">
 
 358             <xsl:text>, </xsl:text>
 
 359             <xsl:value-of select="&tertiary;"/>
 
 362       </rx:begin-index-range>
 
 365       <xsl:call-template name="indexterm"/>
 
 370 <xsl:template match="indexterm[@class='endofrange']">
 
 372     <xsl:when test="$xep.extensions != 0">
 
 374         <xsl:attribute name="ref-id">
 
 375           <xsl:value-of select="@startref"/>
 
 377       </rx:end-index-range>
 
 380       <xsl:call-template name="indexterm"/>
 
 385 <!-- ==================================================================== -->
 
 387 <xsl:template match="indexentry">
 
 389     <!-- don't process 'seeie's from here -->
 
 390     <xsl:apply-templates select="primaryie|secondaryie|tertiaryie|seealsoie"/>
 
 394 <xsl:template match="primaryie">
 
 396     <xsl:apply-templates/>
 
 397     <xsl:if test="following-sibling::seeie">
 
 398       <xsl:text> (</xsl:text>
 
 399       <xsl:call-template name="gentext">
 
 400         <xsl:with-param name="key" select="'see'"/>
 
 402       <xsl:text> </xsl:text>
 
 403       <xsl:apply-templates select="following-sibling::seeie"/>
 
 404       <xsl:text>)</xsl:text>
 
 409 <xsl:template match="secondaryie">
 
 410   <fo:block start-indent="1pc">
 
 411     <xsl:apply-templates/>
 
 412     <xsl:if test="following-sibling::seeie">
 
 413       <xsl:text> (</xsl:text>
 
 414       <xsl:call-template name="gentext">
 
 415         <xsl:with-param name="key" select="'see'"/>
 
 417       <xsl:text> </xsl:text>
 
 418       <xsl:apply-templates select="following-sibling::seeie"/>
 
 419       <xsl:text>)</xsl:text>
 
 424 <xsl:template match="tertiaryie">
 
 425   <fo:block start-indent="2pc">
 
 426     <xsl:apply-templates/>
 
 427     <xsl:if test="following-sibling::seeie">
 
 428       <xsl:text> (</xsl:text>
 
 429       <xsl:call-template name="gentext">
 
 430         <xsl:with-param name="key" select="'see'"/>
 
 432       <xsl:text> </xsl:text>
 
 433       <xsl:apply-templates select="following-sibling::seeie"/>
 
 434       <xsl:text>)</xsl:text>
 
 439 <xsl:template match="seeie">
 
 441     <xsl:apply-templates/>
 
 445 <xsl:template match="seealsoie">
 
 447     <xsl:attribute name="start-indent">
 
 449         <xsl:when test="(preceding-sibling::tertiaryie |
 
 450                          preceding-sibling::secondaryie)[last()]
 
 451                          [self::tertiaryie]">3pc</xsl:when>
 
 452         <xsl:when test="(preceding-sibling::tertiaryie |
 
 453                          preceding-sibling::secondaryie)[last()]
 
 454                          [self::secondaryie]">2pc</xsl:when>
 
 455         <xsl:otherwise>1pc</xsl:otherwise>
 
 458     <xsl:text>(</xsl:text>
 
 459     <xsl:call-template name="gentext">
 
 460       <xsl:with-param name="key" select="'seealso'"/>
 
 462     <xsl:text> </xsl:text>
 
 463     <xsl:apply-templates/>
 
 464     <xsl:text>)</xsl:text>
 
 468 <!-- Determines if an object should be inserted as an fo:inline
 
 469      or an fo:block.  Used for indexterms -->
 
 470 <xsl:template name="inline.or.block">
 
 471   <xsl:param name="parentnode" select=".."/>
 
 473   <xsl:variable name="parent" select="concat('|', local-name($parentnode), '|')"/>
 
 475   <xsl:variable name="block.parents" select="'|answer|appendix|appendixinfo|article|articleinfo|bibliodiv|bibliography|bibliographyinfo|blockinfo|blockquote|bookinfo|callout|caution|chapter|chapterinfo|dedication|example|figure|formalpara|funcsynopsisinfo|glossary|glossaryinfo|glossdef|glossdiv|glossentry|highlights|important|index|indexinfo|info|informalexample|informalfigure|informaltable|itemizedlist|legalnotice|listitem|msgexplan|msgtext|note|objectinfo|orderedlist|partinfo|partintro|preface|prefaceinfo|procedure|qandadiv|qandaset|question|refentry|refentryinfo|referenceinfo|refmeta|refmiscinfo|refsect1|refsect1info|refsect2|refsect2info|refsect3|refsect3info|refsection|refsectioninfo|refsynopsisdiv|refsynopsisdivinfo|revdescription|screeninfo|sect1|sect1info|sect2|sect2info|sect3|sect3info|sect4|sect4info|sect5|sect5info|section|sectioninfo|setindex|setindexinfo|setinfo|sidebar|sidebarinfo|simplesect|step|table|task|taskprerequisites|taskrelated|tasksummary|tip|variablelist|warning|'"/>
 
 478     <xsl:when test="contains($block.parents, $parent)">fo:block</xsl:when>
 
 479     <xsl:when test="$fop1.extensions != 0">fo:wrapper</xsl:when>
 
 480     <xsl:otherwise>fo:inline</xsl:otherwise>