| 
 
Subject: RE: grouping (was: if or template?) From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 12 May 2000 18:24:57 +0200  | 
> I want to then display the Tracker_ID if it is unique followed by all the data for > the specific tracker.
A FAQ: use something like <xsl:for-each select="//tracker-id[not(.=preceding::tracker-id)]">
This is the traditional solution; Steve Muench has just told me about a brilliant alternative using keys:
<xsl:key name="tid" use="tracker-id" select="."/>
<xsl:for-each select="//tracker-id[generate-id(.)=generate-id(key('tid',.)[1])]">
I hope Steve will forgive me for announcing this discovery before he does, I'm quite excited by it because it gives much better performance.
T:\ftemp>type tests.xml <?xml version="1.0"?> <names> <name><given>Julie</given><surname>Holman</surname></name> <name><given>Margaret</given><surname>Mahoney</surname></name> <name><given>Ted</given><surname>Holman</surname></name> <name><given>John</given><surname>Mahoney</surname></name> <name><given>Kathryn</given><surname>Holman</surname></name> <name><given>Ken</given><surname>Holman</surname></name> </names> T:\ftemp>type tests.xsl <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--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>
</xsl:text>
                        <!--select only those for the grouping-->
    <xsl:for-each select="//name[surname=current()/surname]">
      <xsl:sort select="given"/>    <!--sorted within grouping-->
      <xsl:text>   </xsl:text>
      <xsl:value-of select="given"/>   <!--member distinctions-->
      <xsl:text>
</xsl:text>
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>T:\ftemp>saxon tests.xml tests.xsl Holman Julie Kathryn Ken Ted Mahoney John Margaret
-- 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 (Fax:-0995) Web site: XSL/XML/DSSSL/SGML services, training, libraries, products. Practical Transformation Using XSLT and XPath ISBN 1-894049-04-7 Next instructor-led training: 2000-05-11/12,2000-05-15, - 2000-06-12,2000-06-13,2001-01-27
| Current Thread | 
|---|
  | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: grouping (was: if or template?), Steve Muench | Thread | RE: grouping (was: if or template?), Sebastian Rahtz | 
| RE: number question, Kay Michael | Date | RE: number question, Selva, Francis | 
| Month |