xsl-list
[Top] [All Lists]

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

2007-09-21 09:32:13
On Fri, Sep 21 2007 16:28:47 +0100, rocketraman(_at_)fastmail(_dot_)fm wrote:
Tony Graham wrote:
On Fri, Sep 21 2007 08:51:13 +0100, rocketraman(_at_)fastmail(_dot_)fm wrote:
...
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:

I should have provided the output I wanted (obviously ignoring
templates applied to irrelevant nodes). Here it is (basically grouping
all nodes between g1 and g2 into a hierarchical structure).

<r>
  <n1/>
  ...
  <n2/>

  <group>
    <g1/>
    ...
    <g2/>
  </group>

  <group>
    <g1/>
    ...
    <g2/>
  </group>

  <n3/>
  ...
  <n4/>
</r>

I stated in my original email, but didn't emphasize, that there are an
arbitrary number of nodes between g1 - g2, n1 - n2, and n3 - n4 (my
example nodes were badly named).

It may be simpler if you do it all using ">>":

  <xsl:template match="r">
    <xsl:copy>
      <xsl:apply-templates select="*[../g1[1] >> .]"/>
      <xsl:for-each-group
        select="g1[1] |
                *[(. >> ../g1[1]) and (../g2[last()] >> .)] |
                g2[last()]"
        group-ending-with="g2">
        <group>
          <xsl:apply-templates select="current-group()"/>
        </group>
      </xsl:for-each-group>
      <xsl:apply-templates select="*[. >> ../g2[last()]]"/>
    </xsl:copy>
  </xsl:template>


(The logic might be clearer if the predicates used "<<" instead, except
that "<<" has to be written as "&lt;&lt;".)

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

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