commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geerling, Andreas" <>
Subject [JXPath] Write my own sumBigDecimal()-function
Date Tue, 28 Jan 2003 11:07:29 GMT
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 =;
		if (obj instanceof BigDecimal) {
			sum = sum.add((BigDecimal) obj);
	} return sum;

But I would like to use it "within" JXPath as a Function. 

BigDecimal myBetrag = (BigDecimal) context.getValue(

String artikelbezeichnung = (String) context.getValue(
     "positionen[sumBigDecimal(vbetrag) > $minBetrag]/bezeichnung)");

Can someone help me?

Andreas Geerling

View raw message