Rahul Agarwal wrote:

I understand that if I use - <xforms:bind nodeset="A" calculate="sum(B)"/>, the XForms engine will place in element A the sum of elements B.
My intent is to display only some calculated value using <xforms:output>. The calculation is based on values of repetitive nodes in a standard business message. The business message that I receive is from some external source and it may not be possible to get additional nodes ( <ProtectiveDevicePctSum/> ) for calculation and viewing purpose. I need to get some workaround in xforms itself.

Rahul,

If you want to calculate the sum of some elements in your instance with an XForms model item property, you need to store that sum somewhere in your instance. So you need to have an element for that, and this element is not part of your "business document", but is just used by the UI. This is a frequent pattern, so what we when end up doing in many cases is having an instance that look like this:

    <instance>
        <ui>
            <action/>
            <ProtectiveDevicePctSum/>
            ... Other elements used for the UI ...
        </ui>
        <document>
            <PurchaseOrder>
                ... The Business object ...
            </PurchaseOrder>
        </document>
    </instance>

Alternatively, instead of doing an <xforms:output> and referencing <ProtectiveDevicePctSum> in the instance, you can compute the sum in the view with XSLT. Doing something like: <xsl:value-of select="sum(doc('oxf:instance')/Root/ProtectiveDevice/ProtectiveDevicePct)"/>. I tend to prefer the XForms method as it keeps this kind of logic out of the view.

I also wonder, why the incorrect value appears with "sum" and not with "count"?

Assume you have an instance with:

    <form>
        <a>1</a>
        <a>2</a>
        <a>3</a>
    </form>

And you have this bind defined:

    <xforms:bind nodeset="/form/a" calculate="sum(/form/a)"/>

The XForms engine will do this: for each /form/a, evaluate the sum of all /form/a. So /form/a[1] will be initialized to 1+2+3 = 6. Then /form/a[2] will be initialized to 6+2+3 (6 is the new value of a[1]) = 11, and so on. After the bind is evaluated, your instance will look like this, which is not what you want in general:

    <form>
        <a>6</a>
        <a>11</a>
        <a>20</a>
    </form>

Alex


------------------------------------------------------- This SF.Net email is sponsored by: InterSystems CACHE FREE OODBMS DOWNLOAD - A multidimensional database that combines robust object and relational technologies, making it a perfect match for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8 _______________________________________________ orbeon-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/orbeon-user

Reply via email to