Subject: RE: [xsl] for-each and summing based on group From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 5 Jan 2005 23:12:29 -0000 |
Sorry, I should have made it clear that to use XSLT 2.0 you need an XSLT 2.0 processor. For most people this means using Saxon 8.x, though there are a couple of other XSLT 2.0 processors becoming available. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: dmitrik@xxxxxxxxxxxxxx [mailto:dmitrik@xxxxxxxxxxxxxx] > Sent: 05 January 2005 21:33 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] for-each and summing based on group > > I'd rather use 1 if there is a simpler way to calculate > subtotals for this group. > If it is easier with 2, how is it invoked? > > Thanks, > Dmitri > > -----Original Message----- > From: Michael Kay <mike@xxxxxxxxxxxx> > Sent: Jan 5, 2005 2:31 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] for-each and summing based on group > > If you want maximum compatibility when running a 1.0 > stylesheet under a 2.0 > processor, leave the code completely unchanged - i.e. leave > version="1.0". > If you change it to say version="2.0" then you get more rigorous > type-checking: this won't allow implicit type conversions > such as comparing > a string to an integer. In this example you have to change > the code to make > it clear whether you want the integer converted to a string > or vice-versa. > > Michael Kay > http://www.saxonica.com/ > > > -----Original Message----- > > From: dmitrik@xxxxxxxxxxxxxx [mailto:dmitrik@xxxxxxxxxxxxxx] > > Sent: 05 January 2005 19:12 > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > Subject: RE: [xsl] for-each and summing based on group > > > > during a quick online search didn't see any example: > > > > does 1.0 just change to 2.0 in the following? > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:stylesheet > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > version="1.0"> > > > > > > > > -----Original Message----- > > From: Michael Kay <mike@xxxxxxxxxxxx> > > Sent: Jan 5, 2005 1:26 PM > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > Subject: RE: [xsl] for-each and summing based on group > > > > > When changing the xsl from 1.0 to 2.0 there > > > were errors. > > > Is it simpler to do that, or use Muenchian grouping for the > > Customer? > > > > If you were saying that a stylesheet that worked under 1.0 > > didn't work under > > a 2.0 processor, then this is unusual and it would be nice > to know the > > details. > > > > Michael Kay > > http://www.saxonica.com/ > > > > > > > > > > > <xsl:for-each select="Trade"> > > > > > > <xsl:sort select="Customer"/> > > > > > > <tr class="r{position() mod 2}"> > > > > > > <td><xsl:value-of select="Customer"/> </td> > > > > > > <td><xsl:value-of select="TradeId"/><xsl:text/></td> > > > > > > <td><xsl:value-of select="Type"/><xsl:text/></td> > > > > > > <td align="right"> > > > <xsl:value-of select="format-number(sum(Step > > > > > > [concat(substring(MinFlowDate,7),substring(MinFlowDate,1,2),su > > > bstring(MinFlowDate,4,2))>= > > > concat(substring($global,7),substring($global,1,2),substring($ > > > global,4,2))] > > > > > > [concat(substring(MinFlowDate,7),substring(MinFlowDate,1,2),su > > > bstring(MinFlowDate,4,2))< > > > concat(substring($global,7)+3,substring($global,1,2),substring > > > ($global,4,2))] > > > /StepCharge)+ sum(Step > > > > > > [concat(substring(MinFlowDate,7),substring(MinFlowDate,1,2),su > > > bstring(MinFlowDate,4,2))>= > > > concat(substring($global,7),substring($global,1,2),substring($ > > > global,4,2))] > > > > > > [concat(substring(MinFlowDate,7),substring(MinFlowDate,1,2),su > > > bstring(MinFlowDate,4,2))< > > > concat(substring($global,7)+3,substring($global,1,2),substring > > > ($global,4,2))] > > > /StepSetoff) , '###,###,##0')"/> > > > </td> > > > > > > </xsl:for-each> > > > > > > Thanks, > > > Dmitri > > > > > > -----Original Message----- > > > From: Michael Kay <mike@xxxxxxxxxxxx> > > > Sent: Jan 5, 2005 4:50 AM > > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > > Subject: RE: [xsl] for-each and summing based on group > > > > > > First read up about standard grouping techniques such as > > > Muenchian grouping > > > at http://www.jenitennison.com/xslt/grouping > > > > > > Computing a subtotal for each group is then a minor variant of the > > > technique: instead of merely iterating over the items in the > > > group using > > > xsl:for-each, you can assign the node-set comprising the > group to a > > > variable, and then sum over that using the sum() function. > > > > > > Like all grouping problems, it's much easier in 2.0: > > > > > > <xsl:for-each-group select="rows" group-by="columnA"> > > > <xsl:apply-templates select="current-group()"/> > > > <subtotal><xsl:value-of > > > select="sum(current-group()/columnB)"/></subtotal> > > > </xsl:for-each-group> > > > > > > Michael Kay > > > http://www.saxonica.com/ > > > > > > > -----Original Message----- > > > > From: dsk [mailto:dmitrik@xxxxxxxxxxxxxx] > > > > Sent: 05 January 2005 04:09 > > > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > > > Subject: [xsl] for-each and summing based on group > > > > > > > > > > > > within a for-each there might be various sets of values which > > > > produce the > > > > following grid, where val is equal to a number > > > > > > > > a val val val > > > > a val val val > > > > a val val val > > > > b val val val > > > > b val val val > > > > c val val val > > > > c val val val > > > > > > > > what is the best way to insert a sum line for the first > > > > column a, one for b, and one for c. > > > > > > > > is a nested for each needed? or checking to see if the > > > > following value is > > > > not equal to the preceding, then then summing? > > > > > > > > thanks, > > > > Dmitri > > > > > > > > --- > > > > Outgoing mail is certified Virus Free. > > > > Checked by AVG anti-virus system (http://www.grisoft.com). > > > > Version: 6.0.802 / Virus Database: 545 - Release Date: > 11/26/2004
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] for-each and summing base, dmitrik | Thread | [xsl] GUI layout mechanism in XSLT, Ilya Boyandin |
[xsl] use XSLT or XQuery in Saxon?, alan m | Date | Re: [xsl] Usage of key inside a for, Ranjan K. Baisak |
Month |