Need a sumproduct() function

From W3C XForms Group Wiki (Public)


See Custom_XPath_functions.

It should be trivially easy to write a purchase order form without creating unnecessary nodes in the back-end schema.

Right now, if you have a repeat in which each row represents a product to be purchased, the repeat row must show things like the name of the product, the desired quantity, and the unit price. If you know the quantity and the unit price, then the repeat row should also show the line total (the product unitprice*quantity).

If the data schema doesn't have a place for this calculated result (because it is unnecessary data for the server-side transaction), then one might be tempted to use an output with a value attribute to compute and show the product.

But then you want to calculate the before-tax subtotal of the purchase order, well you can't call the XPath sum() function to add up the products because they are being calculated at the UI layer in the outputs, so they are not available to instance data.

A sumproduct() function would solve this. number sumproduct(nodeset A, nodeset B)

For each i, computes each A[i]*B[i] and accumulates the results of the products. The accumulation is returned. Could use zeroes if A and B aren't same size or if A[I] or B[I] is not a number. Or, could return NaN in these cases instead.