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

RE: Keeping a running total?

Subject: RE: Keeping a running total?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 10 Jul 2006 18:21:51 +0100
widget quota
You're out of luck with for-each, because conceptually at least it processes
all the factories in parallel. So you can't accumulate data as you go.
Instead for this kind of problem you need recursion: to a process a list of
factories, process the first factory, then process the rest of the factories
by a recursive call, passing any necessary data (such as your "running
total") as a parameter.

Michael Kay

> -----Original Message-----
> From: Steve [mailto:subsume@xxxxxxxxx] 
> Sent: 10 July 2006 18:12
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Keeping a running total?
> Problem:  I need to make a table of the output required of 4 
> factories next month.
>                   Widgets    Gadgets
> Factory A     2
> Factory B     3
> Factory C                       4
> Factory D                       1
> Widget quota = 5
> Gadget quota = 5
> ---
> My current xsl looks something like.
> <xsl:for-each select="document('factories.xml')//factory">
>        <xsl:variable name="widgets">
>              Has quota been reached? Then return 0.
>              Otherwise, give as many possible without going 
> over the quota.
>        </xsl:variable>
>        <xsl:variable name="gadgets">
>               Has the widget quota been filled?
>               Then start making gadgets!
>                Has this quota been reached? (etc).
>        </xsl:variable>
> 	<tr>
> 		<td><xsl:value-of select="@name" /></td>
> 		<td><xsl:value-of select="$widgets" /></td>
> 		<td><xsl:value-of select="$gadgets" /></td>
> 	</tr>
> </xsl:for-each>
> **Lines which I can't describe in XSL have been translated to 
> English 3.1b
> ----------
> When the quota of Widgets has been reached, I need the 
> factories to start making Gadgets. In the above example the 
> quota is reached at factory B and factory C begins making Gadgets.
> Howto?
> -Steve
> PS: For now I am using a for-each (factory) to iterate 
> through the totals and generate numbers. It seems that 
> templates are beneficial for things such as this, but I have 
> not yet mastered their use and so if this can be more easily 
> done with templates, I'd like to know how.

Current Thread


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.
First Name
Last Name
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.