Subject: Re: [xsl] Multi-grouping with keys (back of book index) From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sat, 21 Oct 2006 15:07:54 -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 XSL 2.0: ... <xsl:key name="list" match="//indexterm" use="@name"/> <xsl:key name="letter" match="//indexterm" use="substring(@name, 1,1)"/> ... <xsl:for-each select="$XML1"> <xsl:for-each select="//indexterm[generate-id(.)=generate-id(key('list', @name))]/@name">
As I see it you are using XSLT 1 techniques in an XSLT 2 stylesheet when XSLT 2 already gives you what you need as native constructs.
T:\ftemp>type philip.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>
T:\ftemp>type philip.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="/"> <xsl:for-each-group select="/*/indexterm" group-by="substring(@name,1,1)"> <xsl:sort select="@name"/> <xsl:text> </xsl:text> <xsl:value-of select="current-grouping-key()"/> <xsl:text> </xsl:text> <xsl:for-each-group select="current-group()" group-by="@name"> <xsl:value-of select="current-grouping-key()"/> <xsl:text> </xsl:text> <xsl:for-each select="current-group()"> <xsl:sort select="."/> <xsl:text/> - <xsl:value-of select="."/><xsl:text> </xsl:text> </xsl:for-each> </xsl:for-each-group> </xsl:for-each-group> </xsl:template>
</xsl:stylesheet> T:\ftemp>xslt2 philip.xml philip.xsl con
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
-- UBL/XSLT/XSL-FO training: Allerxd/Verx Denmark 2006-11-13,17,20/24 UBL International 2006 2006-11-13/17 http://www.ublconference.com World-wide corporate, govt. & user group UBL, XSL, & XML training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Multi-grouping with keys (bac, philip vallone | Thread | RE: [xsl] Multi-grouping with keys , philip vallone |
[xsl] Multi-grouping with keys (bac, philip vallone | Date | Re: [xsl] Multi-grouping with keys , Dimitre Novatchev |
Month |