|
Subject: RE: "sorted" axis (was: Remove duplicates from a node-set accordi ng to content) From: Kay Michael <Michael.Kay@xxxxxxx> Date: Mon, 2 Aug 1999 16:25:04 +0100 |
>
> > 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| PassiveTeX update, Sebastian Rahtz | Thread | Re: "sorted" axis (was: Remove dupl, James Clark |
| PassiveTeX update, Sebastian Rahtz | Date | RE: XSL problem, McKisson, Shawn |
| Month |