commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dplot...@yahoo.com>
Subject Re: [JXPath] Write my own sumBigDecimal()-function
Date Tue, 28 Jan 2003 15:35:54 GMT
Andreas,

You should try to use an ExtensionFunction.  What exactly is the issue
with iteration?

- Dmitri


--- "Geerling, Andreas" <andreas.geerling@sap.com> wrote:
> I am trying to write a function sumBigDecimal() similar to the sum()
> function. 
> First I tried to create a ExtensionFunction, but i have the problem
> to iterate the values.
> 
> Only with Java, i would do it like this:
> 
> public static BigDecimal sumBigDecimal(JXPathContext context,String
> xpath) {
> 	Object obj = null;
> 	BigDecimal sum = new BigDecimal("0");
> 	Iterator iter = context.iterate(xpath);
> 	while (iter.hasNext()) {
> 		obj = iter.next();
> 		if (obj instanceof BigDecimal) {
> 			sum = sum.add((BigDecimal) obj);
> 		}
> 	} return sum;
> }
> 
> But I would like to use it "within" JXPath as a Function. 
> Examples:
> 
> BigDecimal myBetrag = (BigDecimal) context.getValue(
> 
>
"myf:sumBigDecimal(positionen[freieAttribute/warengruppe='AA']/vbetrag)");
> 
> String artikelbezeichnung = (String) context.getValue(
>      "positionen[sumBigDecimal(vbetrag) > $minBetrag]/bezeichnung)");
> 
> Can someone help me?
> 
> Andreas Geerling
> 
> 
> --
> To unsubscribe, e-mail:  
> <mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:commons-user-help@jakarta.apache.org>
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Mime
View raw message