FileDocCategorySizeDatePackage
FuncSum.javaAPI DocJava SE 6 API1934Tue Jun 10 00:23:16 BST 2008com.sun.org.apache.xpath.internal.functions

FuncSum

public class FuncSum extends FunctionOneArg
Execute the Sum() function.
xsl.usage
advanced

Fields Summary
static final long
serialVersionUID
Constructors Summary
Methods Summary
public com.sun.org.apache.xpath.internal.objects.XObjectexecute(com.sun.org.apache.xpath.internal.XPathContext xctxt)
Execute the function. The function must return a valid object.

param
xctxt The current execution context.
return
A valid XObject.
throws
javax.xml.transform.TransformerException


                            
       
  

    DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
    double sum = 0.0;
    int pos;

    while (DTM.NULL != (pos = nodes.nextNode()))
    {
      DTM dtm = nodes.getDTM(pos);
      XMLString s = dtm.getStringValue(pos);

      if (null != s)
        sum += s.toDouble();
    }
    nodes.detach();

    return new XNumber(sum);