RE: grouping (was: if or template?)

Subject: RE: grouping (was: if or template?)
From: Sebastian Rahtz <sebastian.rahtz@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 May 2000 11:22:34 +0100 (BST)
G. Ken Holman writes:
 >              <!--prepare to examine all names valued by surname-->
 > <xsl:key name="surnames" match="name" use="surname"/>
 > <xsl:template match="/">                         <!--root rule-->
 >              <!--select only those name elements whose unique
 >                  generated id is equal to the generated id of the
 >                  first of the key members with the same surname-->
 >    <xsl:for-each
 >          select="//name[generate-id(.)=
 >                         generate-id(key('surnames',surname)[1])]">
 >      <xsl:value-of select="surname"/>     <!--show the grouping-->
 >      <xsl:text>&#xd;&#xa;</xsl:text>
 >                          <!--select only those for the grouping-->
 >      <xsl:for-each select="//name[surname=current()/surname]">
 >        <xsl:sort select="given"/>    <!--sorted within grouping-->

you can speed this up again, I believe, by using the key again

     <xsl:variable name="surname" select="surname"/>
     <xsl:for-each select="key('surnames',$surname)">


that is to say, for every unique surname, consult the key again to
get the list of people with that surname. that way, you do not have to 
navigate the tree again at all, since the list of relevant nodes is
already known.


 XSL-List info and archive:

Current Thread