* xmlXPathSumFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the sum() XPath function * number sum(node-set) * The sum function returns the sum of the values of the nodes in * the argument node-set. */
| 8567 | * the argument node-set. |
| 8568 | */ |
| 8569 | void |
| 8570 | xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
| 8571 | xmlXPathObjectPtr cur; |
| 8572 | int i; |
| 8573 | double res = 0.0; |
| 8574 | |
| 8575 | CHECK_ARITY(1); |
| 8576 | if ((ctxt->value == NULL) || |
| 8577 | ((ctxt->value->type != XPATH_NODESET) && |
| 8578 | (ctxt->value->type != XPATH_XSLT_TREE))) |
| 8579 | XP_ERROR(XPATH_INVALID_TYPE); |
| 8580 | cur = valuePop(ctxt); |
| 8581 | |
| 8582 | if ((cur->nodesetval != NULL) && (cur->nodesetval->nodeNr != 0)) { |
| 8583 | for (i = 0; i < cur->nodesetval->nodeNr; i++) { |
| 8584 | res += xmlXPathNodeToNumberInternal(ctxt, |
| 8585 | cur->nodesetval->nodeTab[i]); |
| 8586 | } |
| 8587 | } |
| 8588 | valuePush(ctxt, xmlXPathCacheNewFloat(ctxt, res)); |
| 8589 | xmlXPathReleaseObject(ctxt->context, cur); |
| 8590 | } |
| 8591 | |
| 8592 | /** |
| 8593 | * xmlXPathFloorFunction: |
nothing calls this directly
no test coverage detected