Re: [xsl] Grouping problem (?)

Subject: Re: [xsl] Grouping problem (?)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 15 Sep 2003 12:03:35 +0100


> [step 1]
> Show the first person's name and address
> [step 2]
> For each person,
>     if the address is the same as the first listed person's
>           then display the name in the same table as the first person's
> information, adding '1' to the first person's number
> [step 3]
> For each person
>     If the address is different than the first listed person's
>         then display the name in a new table with the number incremented by
> 1.
> 

That description (which is very imperative, you'd be better giving a
declarative, functional, description when thinking about xslt)
doesn't seem to match your suggested output.
which appears to be all in one table (despite step 3) and the number
incremented for all perople whether or not they have the same address
(despite your step 2)

You want to use a grouping technique (eg look up muenchian grouping
on Jeni's site) with a key that expresses the address eg

<xsl:key name="x" match="address"
use="concat(street,',',city,',',state,',',postcode,',',country)"/>

The details will depend a bit on whet exactly your criteria are, and
whether you can assume that the input document is already in the right
order, or whether you first need to reorder to bring people with the
same address together.

David


one comment more or less unrelated to your grouping problem.

> <xsl:for-each select="//person

you probably don't (hardly ever) want to use // as it is very expensive
causing the system to search the entire document to arbitrary depth
looking for person elements. You may know there areno person elements
inside <state>, but the system doesn't.


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread