Re: [docbook-apps] Permuted Index, may be OT

From
Jirka Kosek <>
Date
2004-03-26T15:59:33+00:00
ID
Thread
Re: [docbook-apps] Permuted Index, may be OT
Riaan Bredenkamp wrote:

> Say "The fat cat sleeps." is a term I want to create list in an index.
> in a normal index there would be one entry :
> T
> "The fat cat sleeps." -- 15

And currenty you have marked this term as <indexterm><primary>The fat
cat sleeps</primary></indexterm>?

> In a permuted index there would be multiple entries:
> C
> cat - the fat sleeps. -- 15
> F
> fat - the cat sleeps. -- 15
> S
> sleeps - the fat cat. -- 15
> T
> The - fat cat sleeps. -- 15

If so, you can create preprocessing step which will create seperate
indexterms for each word. Something like:

<xsl:stylesheet ...>

<!-- Identity copy -->
<xsl:template match="@*|node()">
    <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="indexterm">
    <!-- Duplicate current indexterm -->
    <xsl:copy-of select="."/>
    <!-- Create permutations -->
    <xsl:call-template name="perm">
      <xsl:with-param name="text" select="string(primary)"/>
    </xsl:call-template>
</xsl:template>

<xsl:template name="perm">
    <xsl:param name="text"/>
    <xsl:variable name="first" select="substring-before(concat($text, '
'), ' ')"/>
    <xsl:variable name="rest" select="substring-after($text, ' ')"/>

    <indexterm><primary><xsl:value-of 
select="$first"/></primary></indexterm>

    <xsl:if test="$rest != ''">
      <xsl:call-template name="perm">
        <xsl:with-param name="text" select="$rest"/>
      </xsl:call-template>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

Then you will apply this stylesheet to your DocBook document to get
temporary DocBook document with index permutations. You will then
process this temporary document as normal DocBook document.

-- 
-----------------------------------------------------------------
    Jirka Kosek  	
    e-mail: 
    http://www.kosek.cz