Re: [xsl] Apply for-each-group to a node subset

Subject: Re: [xsl] Apply for-each-group to a node subset
From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 21 Sep 2007 11:36:27 +0100
On Fri, Sep 21 2007 08:51:13 +0100, rocketraman@xxxxxxxxxxx wrote:
> I tried to simplify some of the expressions by using nested predicates
> but for some reason that didn't work e.g.
>     <!-- process nodes after group -->
>     <xsl:apply-templates select="*[preceding-sibling::g2[last()]]"/>

I'm still trying to get my head around what you want to do with your
template, but the likely reasons that your simplification doesn't work

 - The preceding-sibling axis is a 'reverse axis' [1], so the
   immediately preceding sibling is at position 1 in the context for the
   "[last()]" predicate, not (necessarily) the last position.

 - You are selecting every child element that has a preceding 'g2'
   sibling (since if there are any preceding 'g2' siblings, there will
   be a last one of them even when there's only one).

You may do better with:

      select="*[preceding-sibling::*[1][local-name() = 'g2']]"/>

which selects child elements whose first preceding sibling element (of
any type) is a 'g2'.


Tony Graham.

Menteith Consulting Ltd             Registered in Ireland - No. 428599
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Menteith Consulting -- Understanding how markup works


Current Thread