This is the mail archive of the mailing list .

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: grouping (was: if or template?)

(I wrote this post before finding Steve's example just now from Wednesday 
in my archive; I'll still post it since it is what I did this evening for 
myself to help me understand what he has developed. I think this is quite 

At 00/05/08 17:54 +0100, Kay Michael wrote:
> > 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="."/>
>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.

This is a truly kewl idea ... but ... isn't the syntax above incorrect?

Wouldn't the declaration of the key be as follows?

     <xsl:key name="tid" match="tracker-id" use="."/>

I apologize in advance if this sounds pedantic, but readers might get 
confused about which attribute is the matching attribute (match=) and which 
is the selection (use=) since the cited example had it backwards and 
incorrectly named.

I have an example below.

I hope this helps.

................... Ken

T:\ftemp>type tests.xml
<?xml version="1.0"?>
T:\ftemp>type tests.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=""

<xsl:output method="text"/>

             <!--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:value-of select="surname"/>     <!--show the grouping-->
                         <!--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-->


T:\ftemp>saxon tests.xml tests.xsl

G. Ken Holman          
Crane Softwrights Ltd.   
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

 XSL-List info and archive:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]