[xsl] Generating book index via attributes...

Subject: [xsl] Generating book index via attributes...
From: "Dave Carvell" <dave.carvell@xxxxxxxxx>
Date: Fri, 9 Apr 2010 13:15:29 -0400
(Using XMLSpy Enterprise Edition version 2010 rel.  2, xsl 1.0)

<?xml version="1.0" encoding="utf-8"?>
<docroot>
    <chapter>
        <title>
            Brakes
            <indxref refs1="Brakes"/>
        </title>
         <subchapter>
            <title>
                Drum type Brakes
                <indxref refs1="Brakes" refs2="drum"/>
            </title>
            <para>stuff...
                <indxref refs1="Brakes" refs2="drum" refs3="diagram"/>
       </para>
       ...

I need to generate an index. For now, I just need a hierarchical listing.

Here is what I get...

Brakes

....drum

........diagram

........terminology

....disc

....failure

........symptoms

........dangers

Engine

....gasoline

....diesel


There is some conflict between entries:

Here is the code. I am very new to this, but it seems to me the difficulty is
due in part to the fact that the attributes are not nested.

<indxref refs1="Brakes" refs2="failure" refs3="symptoms"/>
<indxref refs1="Engine" refs2="failure" refs3="symptoms"/>

I don't get entries for either failures or symptoms under Engine.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:key name="refs1Key" match="indxref/@refs1" use="../@refs1"/>
<xsl:key name="refs2Key" match="indxref/@refs2" use="../@refs2"/>
<xsl:key name="refs3Key" match="indxref/@refs3" use="../@refs3"/>

<xsl:template match="docroot">
            <xsl:apply-templates select="//indxref/@refs1" mode="group">
                        <xsl:sort select="../@refs1" />
            </xsl:apply-templates>
</xsl:template>

<xsl:template match="@refs1" mode="group">

                                    <xsl:apply-templates select="../@refs2"
mode="group">
                                                <xsl:sort select="../@refs2"
/>
                                    </xsl:apply-templates>

                                    <xsl:variable name="primaries"
select="key('refs1Key', .)" />
                                    <xsl:variable name="firstPrimary"
select="$primaries[1]" />
                                    <xsl:if test="generate-id() =
generate-id($firstPrimary)">
                                                <br/><xsl:value-of
select="../@refs1" /><br/>
                                    </xsl:if>

</xsl:template>

<xsl:template match="@refs2" mode="group">


                                    <xsl:apply-templates select="../@refs3"
mode="group">
                                                <xsl:sort select="../@refs3"
/>
                                    </xsl:apply-templates>

                                    <xsl:variable name="secondaries"
select="key('refs2Key', .)" />
                                    <xsl:variable name="firstSecondary"
select="$secondaries[1]" />

                                    <xsl:if test="generate-id() =
generate-id($firstSecondary)">
                                                <br/>....<xsl:value-of
select="../@refs2" /><br/>
                                    </xsl:if>

</xsl:template>

<xsl:template match="@refs3" mode="group">
            <xsl:variable name="tertiaries" select="key('refs3Key', .)" />
            <xsl:variable name="firstTertiary" select="$tertiaries[1]" />
           
            <xsl:if test="generate-id() = generate-id($firstTertiary)">
                        <br/>........<xsl:value-of select="../@refs3" /><br/>
            </xsl:if>
</xsl:template>


</xsl:stylesheet>

Any help would be greatly appreciated.

Dave Carvell

O'NEIL & ASSOCIATES, INC.
495 Byers Rd.
Miamisburg, Ohio 45342-3662
Phone: (937) 865-0846 ext. 3030
Mobile: (937) 974-9566
Fax: (937) 865-0789 or -5858
E-mail: dave.carvell@xxxxxxxxx  


**********************************************************************
Confidentiality Notice
The information contained in this e-mail is confidential and intended for use
only by the person(s) or organization listed in the address. If you have
received this communication in error, please contact the sender at O'Neil &
Associates, Inc., immediately. Any copying, dissemination, or distribution of
this communication, other than by the intended recipient, is strictly
prohibited.
**********************************************************************

Current Thread