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

RE: "sorted" axis (was: Remove duplicates from a node-set ac

Subject: RE: "sorted" axis (was: Remove duplicates from a node-set according to content)
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Mon, 2 Aug 1999 16:25:04 +0100
xsl for each remove duplicates
> 
> > something like:
> > 
> > process node set X sorted by Y then Z
> > -- for each group with common Y do
> > -- <h2>Y</h2>
> > ---- for each group with common Z do
> > ---- <h3>Z</h3><ul>
> > ------- for each item do
> > ------- <li>stuff</li>
> > ------- end for
> > ---- </ul>
> > ---- end for
> > ---<hr/>
> > -- end for
> > end process
> 
> Couldn't you think of it as?
> 
> for each member of (node set X sorted by Y then Z, grouped by 
> Y then by
> Z)
> -- <h2>Y</h2>
> ---- for each member of the current group do
> ---- <h3>Z</h3><ul>
> ------- for each member of the current group do
> ------- <li>stuff</li>
> ------- end for
> ---- </ul>
> ---- end for
> ---<hr/>
> -- end for
> end for
> 
You could think of it that way, but I'm not sure I see the benefit in
"factoring out" the group definitions to the top.

Another way of doing it, which solves the counting/totalling problem, avoids
the need for xsl:item, and allows use of apply-templates, is to assign a
node-set variable to each group in turn:

<xsl:for-each-group name="annual-sales" select="$all-sales"
group-by="@year">
   <xsl:sort select="@year"/>
   <h1>Sales in <xsl:value-of select="@year"/></h1>
   <xsl:for-each-group name="monthly-sales" select="$annual-sales"
group-by="@month">
      <xsl:sort select="@month"/>
      <h2>Sales in <xsl:value-of select="month-name(@month)"/></h2>
      <xsl:for-each select="$monthly-sales">
		<p><xsl:value-of select="concat(@customer, ': ',
@sales-value)"/></p>
      </xsl:for-each>
      <p>Total sales for the month:
		 <xsl:value-of
select="sum($monthly-sales/@sales-value)"/></p>
   </xsl:for-each-group>
   <p>Total sales for the year:
		 <xsl:value-of
select="sum($annual-sales/@sales-value)"/></p>
</xsl:for-each-group>


Mike K


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.