[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Nested for-each-group

Subject: RE: Nested for-each-group
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 28 Sep 2004 13:10:23 +0100
xsl nested for each
group-starting-with and group-ending-with partition the population: the
first/last item in the population starts/ends a group whether or not it
matches the pattern. 

The simplest way to discard the spurious groups in this case is probably to
do 

xsl:if test="position()=last()" 

in the outer group, and

xsl:if test="position()=1"

in the inner group.

An interesting way of tackling the problem. I think I would have used
"intersect":

<div>
 <xsl:value-of select="
    sum (    
      (col[@colname=$s]/(.|following-sibling::col)
               intersect
       col[@colname=$e]/(.|preceding-sibling::col))/@width)"/>
</div>

Unless I thought about it more carefully (!), in which case I would use a
predicate of the form:

sum(col[. is $S or . is $E or (. >> $S and . << $E)])

Yet another solution:

for $s in index-of(col/@colname, $start),
    $e in index-of(col/@colname, $end)
return
    sum(subsequence(col/@width, $s, $e - $s + 1)), 


Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Andrew Welch [mailto:ajwelch@xxxxxxxxxxxxxxx] 
> Sent: 28 September 2004 11:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Nested for-each-group
> 
> 
> Hi all,
> 
> Given this xml:
> 
> <tgroup>
> 	<col colname="C.HPC" width="17"/>
> 	<col colname="C.HPB" width="23"/>
> 	<col colname="C.HPA" width="29"/>
> 	<col colname="C.I0F" width="17"/>
> 	<col colname="C.I0E" width="14"/>
> 	<spanspec namest="C.HPC" nameend="C.I0F"/>
> 	<spanspec namest="C.HPC" nameend="C.I0E"/>
> </tgroup>
> 
> I'm trying to sum the colwidths specified by the spanspecs.  I used to
> use a recursive template, which I'm trying to replace using a nested
> for-each-group:
> 
> <xsl:template match="spanspec">
>     <xsl:variable name="namest" select="@namest"/>
>     <xsl:variable name="nameend" select="@nameend"/>
> 
>     <xsl:for-each-group select="preceding-sibling::col"
> group-starting-with="*[@colname = $namest]">
>         <xsl:for-each-group select="current-group()"
> group-ending-with="*[@colname = $nameend]">
>       		<div><xsl:value-of
> select="sum(current-group()/@width)"/></div>
>       	</xsl:for-each-group>
>     </xsl:for-each-group>
> 
> </xsl:template>
> 
> However, this produces:
> 
> 	<div>86</div><div>14</div>
> 	<div>100</div>
> 
> I don't understand why I'm getting the "<div>14</div>" output?  I know
> it's part of the outer group, but it shouldn't be part of the inner
> group.  Any ideas why its there?
> 
> cheers
> andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.