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

Subject: Re: [xsl] Apply for-each-group to a node subset
From: Abel Braaksma <>
Date: Fri, 21 Sep 2007 17:37:45 +0200
Raman Gupta wrote:

     <!-- process nodes after group -->
     <xsl:apply-templates select="*[preceding-sibling::g2[last()]]"/>

The way I read this is: apply templates to all the nodes that have the
LAST g2 as a preceding sibling, which should apply templates to all
nodes n3 to n4.

Close, but not close enough. This would be of interest to Mathieu Malaterre as well, if he is listening You are expressing:

Take all nodes


a sibling preceding myself and with the name 'g2'


a position that is the last in the list (the list being "siblings preceding myself and with the name 'g2' ")

This means in even better English: select all nodes that has a preceding sibling with the name 'g2'. In your statement, last() does not do anything and is redundant.

This is just the same as when you would make the following xpath:


Here, too, is last() meaning just the same as [1], or leaving out the predicate completely.

BTW, having to select the last 'g2' in your English sentence means the g2 on the preceding/following sibling access, not being on the following sibling axis (i.e., not being in front of it). Expressed as:


meaning: not having any following sibling of type g2. Which is basically what you said, I think.

-- Abel Braaksma

Current Thread