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

Recursive sums in xslt 1.0

Subject: Recursive sums in xslt 1.0
From: Daniel O'Donnell <daniel.odonnell@xxxxxxxx>
Date: Sun, 13 Mar 2005 11:20:01 -0700
recursive sums
Hi,
I'm returning to a problem I asked a couple of weeks ago about node tests <http://www.biglist.com/lists/xsl-list/archives/200503/msg00088.html>. I've been working through the XSL 2.0 and XSL 1.0 suggestions proposed at the time by David Carlisle <http://www.biglist.com/lists/xsl-list/archives/200503/msg00089.html> and Wendell Piez <http://www.biglist.com/lists/xsl-list/archives/200503/msg00159.html>. I've listed the problem at the end of this e-mail.


The xslt 1.0 solution proposed was:

in xslt1 if you want to store an expression that is going to be
re-evaluated you need to put it in a named template. Then you could call
that so long as you replaced sum(..) with a recursive template that
iterated over the nodes calculating the sum and calling your named
templates.

I understand the named template, of course. I don't understand the second sentence, though. How would this work? I'm raising the question here rather than privately, because it seems like an important technique that might be useful (and difficult) for others like myself you are (now) probably more than beginners but less than experts.



The problem from my original e-mail:
The context is a financial xslt file that outputs itemised monthly
reports from an unitemised year-to-date xml file.  For each item in the
output file, I need to do two tests: one for date and the other for some
other feature (usually party [i.e. payer/payee]). This would be an
example with no parameters or variables:


<xsl:variable name="actualelectricity"> <xsl:value-of select="sum(/statement/item[date >= 20050228 and party[contains('DEML')]]/amount)"/> </xsl:variable>


What I want to do is turn the two expressions in the test into independent variables so that I could do something like this:


<xsl:variable name="actualelectricity"> <xsl:value-of select="sum(/statement/item[$datetest and $electricitytest]/amount)"/> </xsl:variable>

Where

datetest = (date >= 20050228)

and

electricitytest = (party[contains('DEML')])

The reason for doing this is that it allows me to reuse the category tests (i.e. the party[contains()]-type tests) independently of the date tests: for year-to-date summaries, and for a miscellaneous class that consists of anything that is not identified by an explicit category test.


--
Daniel Paul O'Donnell, PhD
Associate Professor of English
University of Lethbridge
Lethbridge AB T1K 3M4
Tel. (403) 329-2377
Fax. (403) 382-7191
E-mail <daniel.odonnell@xxxxxxxx>
Home Page <http://people.uleth.ca/~daniel.odonnell/>
The Digital Medievalist Project: <http://www.digitalmedievalist.org/>

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.