[xsl] Multi-grouping with keys (back of book index)

Subject: [xsl] Multi-grouping with keys (back of book index)
From: "philip vallone" <philip.vallone@xxxxxxxxxxx>
Date: Sat, 21 Oct 2006 14:54:27 -0400
Hi, I am building a back of the book index using keys and grouping. I am
able to group the <indexterms> to the @name attribute, but I can't figure
out how to group the @name attribute to its respective letter. My desired
output is:

Desired output:

E
E190
-Aircraft Tail
-Landing Gear
Election
-voting

G
GMM
-Aircraft Logbook Entry 
-MX-4 Deffered Items 

S
Smith Airways
-MEL Policy and Revision number




Here is my XML:


<book>
<indexterm name="GMM">Aircraft Logbook Entry</indexterm>
<indexterm name="Smith Airways">MEL Policy and Revision number</indexterm>
<indexterm name="GMM">MX-4 Deffered Items</indexterm>
<indexterm name="E190">Aircraft Tail</indexterm>
<indexterm name="E190">Landing Gear</indexterm>
<indexterm name="Election">Voting</indexterm>
</book>

Here is my XSL 2.0:

<xsl:output method="html"/>
	<xsl:variable name="XML1" select="/"/>
	<xsl:key name="list" match="//indexterm" use="@name"/>
	<xsl:key name="letter" match="//indexterm" use="substring(@name,
1,1)"/>
	<xsl:template match="/">
		<html>
			<head>
				<title>Manual Index</title>
			</head>
			<style type="text/css">
h2 {font-family:verdana,helvetica,sans-serif;font-size:13pt}
li {font-family:verdana,helvetica,sans-serif;font-size:11pt}
</style>
			<body>
				<xsl:for-each select="$XML1">
					<xsl:for-each
select="//indexterm[generate-id(.)=generate-id(key('list', @name))]/@name">
						<xsl:sort/>
						<xsl:variable name="key"
select="translate(substring(.,1,1),
                                  'abcdefghijklmnopqrstuvwxyz', 
                                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
						<xsl:value-of
select="$key"/>
						<xsl:for-each
select="//indexterm[generate-id(.)=generate-id(key('list', @name))]/@name">
							<xsl:sort/>
							<xsl:variable
name="get" select="../@name"/>
							<h2>
	
<xsl:value-of select="."/>
							</h2>
							<ul>
	
<xsl:for-each select="key('list', $get)">
	
<xsl:sort/>
									<li>
	
<xsl:value-of select="."/>
	
</li>
	
</xsl:for-each>
							</ul>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:for-each>
			</body>
		</html>
	</xsl:template>



Thanks for the help.

Phil

Current Thread