Altova Mailing List Archives
>xsl-list Archive Home
>Recent entries
>Thread Prev - [xsl] Multi-grouping with keys (back of book index)
[Thread Next]
Re: [xsl] Multi-grouping with keys (back of book index)
To:
Date: 10/21/2006 7:27:00 PM
This is XSLT 2.0, so it is much more easier -- in particular one doesn't need to use keys and the Muenchian method: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="text"/> <xsl:template match="/*"> <xsl:for-each-group select="indexterm" group-by="substring(@name,1,1)"> <xsl:sort select="current-grouping-key()"/> <xsl:text>

</xsl:text> <xsl:value-of select="current-grouping-key()"/> <xsl:for-each-group select="current-group()" group-by="@name"> <xsl:sort select="current-grouping-key()"/> <xsl:text>
</xsl:text> <xsl:value-of select="current-grouping-key()"/> <xsl:for-each select="current-group()[normalize-space()]"> <xsl:value-of select="concat('
-',.)"/> </xsl:for-each> </xsl:for-each-group> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play On 10/21/06, philip vallone <philip.vallone@xxxxxxxxxxx> wrote: 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 -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play
Disclaimer
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

