1 16 19 package com.sun.org.apache.xpath.internal.functions; 20 21 import com.sun.org.apache.xml.internal.dtm.DTM; 22 import com.sun.org.apache.xml.internal.dtm.DTMIterator; 23 import com.sun.org.apache.xml.internal.utils.XMLString; 24 import com.sun.org.apache.xpath.internal.XPathContext; 25 import com.sun.org.apache.xpath.internal.objects.XNumber; 26 import com.sun.org.apache.xpath.internal.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 |