This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: grouping headers
- To: "Sullivan, Dan" <dsullivan at develop dot com>
- Subject: Re: [xsl] grouping headers
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 24 Aug 2001 14:25:05 +0100
- CC: XSL-List at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <94FD4438D783D74EA86DC692E776C12774CC28@la-infoserver.develop.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Dan,
> <xsl:apply-templates
> select="person[preceding-sibling::person[city]!=city]">
I think you meant:
person[preceding-sibling::person/city != city]
but you have to be a bit careful when you use != with node sets. The
above predicate will test whether there are *any* preceding person
elements whose city is not equal to the context person's city. So if
you have:
<person><city>Amsterdam</city></person>
<person><city>Madrid</city></person>
<person><city>Amsterdam</city></person>
<person><city>Madrid</city></person>
then it will actually be false for the first person (because it there
are no person elements before it), and true for the rest of the person
elements (because they each have at least one preceding person with a
different city).
What you want is:
person[not(preceding-sibling::person/city = city)]
in which the predicate tests whether it's not the case that there is a
preceding person's city equal to the context person's city, i.e. those
that are first with a particular city. This is true for the first and
second person in the above XML, and false for the other two.
(It's usually better still to use keys because they're more efficient,
but that's a different issue.)
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list