RE: [xsl] Comparing previous

Subject: RE: [xsl] Comparing previous
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 19 Mar 2002 08:43:37 -0000
> I'm hoping someone can help me. Here's my problem:
>
> I am accessing a sorted node list using apply-templates and wish to
> compare against the previous node in the sorted node set when
> accessing
> the current node in the matched template.

There is no way of doing this.

> I was thinking self::node()[position()-1], but this doesn't seem
> to work.

No, this definitely won't work, for several reasons. self::node() always
selects a single node, and the numeric predicate [position()-1] is short for
[position()=position()-1] which is always false.
>
> FWIW there are multiple wk_wks nodes and multiple
> wk_wks_parcel nodes as
> children to the wk_wks nodes. wk_wks_parcel nodes may be
> repeated across
> multiple  wk_wks nodes. My goal is to display them all in a list but
> only once.
>
For all problems that involve eliminating duplicates or grouping, look at
Muenchian grouping techniques as described in Chapter 9 of my book, or at
http://www.jenitennison.com/xslt/grouping.

It may be that in this case a simpler two-pass solution is appropriate: sort
the original data into a result tree fragment, then process this fragment
(using xx:node-set()), testing each node with the condition xsl:if
test="not(@x = preceding-sibling::*[1]/@x)".

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx


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


Current Thread