xsl-list
[Top] [All Lists]

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

2007-09-21 03:36:58
On Fri, Sep 21 2007 08:51:13 +0100, rocketraman(_at_)fastmail(_dot_)fm 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
are:

 - 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:

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

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

Regards,


Tony Graham.
======================================================================
Tony(_dot_)Graham(_at_)MenteithConsulting(_dot_)com   
http://www.menteithconsulting.com

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
======================================================================

[1] http://www.w3.org/TR/xpath20/#doc-xpath-ReverseAxis

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--