Re: [xsl] Generating book index via attributes...

Subject: Re: [xsl] Generating book index via attributes...
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 09 Apr 2010 19:54:57 +0200
Dave Carvell wrote:
(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.

Maybe the following does what you want but I am guessing as to what you want to achieve:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

<xsl:output method="html" indent="yes"/>

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

  <xsl:key name="refs2Key"
           match="indxref/@refs2"
           use="concat(../@refs1, '|', .)"/>

  <xsl:key name="refs3Key"
           match="indxref/@refs3"
           use="concat(../@refs1, '|', ../@refs2, '|', .)"/>

<xsl:template match="docroot">
<xsl:apply-templates select="//indxref/@refs1[generate-id() = generate-id(key('refs1Key', .)[1])]" mode="group">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="@refs1" mode="group">
<xsl:value-of select="."/>
<br/>
<xsl:apply-templates select="key('refs1Key', .)/../@refs2[generate-id() = generate-id(key('refs2Key', concat(../@refs1, '|', .))[1])]" mode="group">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="@refs2" mode="group">
<br/>....<xsl:value-of select="." /><br/>
<xsl:apply-templates select="key('refs2Key', concat(../@refs1, '|', .))/../@refs3[generate-id() = generate-id(key('refs3Key', concat(../@refs1, '|', ../@refs2, '|', .))[1])]" mode="group">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:template>


  <xsl:template match="@refs3" mode="group">
    <br/>........<xsl:value-of select="." /><br/>
  </xsl:template>

</xsl:stylesheet>

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread