1 16 19 package org.apache.xpath.functions; 20 21 import org.apache.xml.dtm.DTM; 22 import org.apache.xml.dtm.DTMIterator; 23 import org.apache.xml.utils.XMLString; 24 import org.apache.xpath.XPathContext; 25 import org.apache.xpath.objects.XNumber; 26 import org.apache.xpath.objects.XObject; 27 28 32 public class FuncSum extends FunctionOneArg 33 { 34 35 43 public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 44 { 45 46 DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); 47 double sum = 0.0; 48 int pos; 49 50 while (DTM.NULL != (pos = nodes.nextNode())) 51 { 52 DTM dtm = nodes.getDTM(pos); 53 XMLString s = dtm.getStringValue(pos); 54 55 if (null != s) 56 sum += s.toDouble(); 57 } 58 nodes.detach(); 59 60 return new XNumber(sum); 61 } 62 } 63 | Popular Tags |