xsl-list
[Top] [All Lists]

[xsl] Re: How to create index entry in xsl file?

2008-12-23 12:56:30
Hello Vasu,

I am not using docbook dtd. However, I am using DITA dtd. Will this help me?

Awaiting for your reply!

Thanks,
Kalpana

On 12/22/08, Kalpana Pathak <pathak(_dot_)kalpana(_at_)gmail(_dot_)com> wrote:
Hello everyone,

I would like to generate the indexes in the PDF output. I typed the
following elements in the xsl file, but it is giving me error. Can
someone guide me to what are the attributes/parameters i need to put
in the xsl file to generate the index.

 <xsl:key name="letter" match="indexterm" use="substring(primary,1,1)"/>

 <xsl:key name="letter" match="indexterm"
          use="translate(substring(primary,1,1),
                         'abcdefghijklmnopqrstuvwxyz',
                       'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
 <xsl:apply-templates select="//indexterm[count(.|
                                key('letter',
                                  translate(substring(primary,1,1),
                                    'abcdefghijklmnopqrstuvwxyz',
                                    'ABCDEFGHIJKLMNOPQRSTUVWXYZ'))[1])
                                = 1]"
                      mode="index-div">
   <xsl:sort select="translate(primary, 'abcdefghijklmnopqrstuvwxyz',
                                        'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
 </xsl:apply-templates>
 <xsl:key name="primary" match="indexterm" use="primary"/>

 <xsl:template match="indexterm" mode="index-div">
   <!-- Get the group key (ie. first letter of index terms in this group -->
   <xsl:variable name="key"
                 select="translate(substring(primary,1,1),
                                   'abcdefghijklmnopqrstuvwxyz',
                                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>

   <!-- Output label for current index group -->
   <xsl:value-of select="$key"/>

   <xsl:apply-templates select="key('letter', $key)
                                [count(.|key('primary',primary)[1])=1]"
                        mode="index-primary">
     <xsl:sort select="translate(primary,
                                 'abcdefghijklmnopqrstuvwxyz',
                                 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
   </xsl:apply-templates>
 </xsl:template>

 <xsl:key name="primary" match="indexterm" use="primary"/>

  <xsl:template match="indexterm" mode="index-primary">

   <!-- Find all occurences of index term -->
   <xsl:variable name="refs" select="key('primary', primary)"/>

   <!-- Output text of index term -->
   <xsl:value-of select="primary"/>

   <xsl:for-each select="$refs[not(secondary)]">
     <!-- Create page number reference (print) or link with back
          reference (HTML) to each occurrence of the index term -->
   </xsl:for-each>

   <xsl:if test="$refs/secondary">
      <!-- Process secondary level entries -->
   </xsl:if>
  </xsl:template>

Thanks in advance,
Kalpana


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>