Skip to content

Instantly share code, notes, and snippets.

@ebruchez ebruchez/sums.xhtml
Last active Dec 21, 2015

Embed
What would you like to do?
<xh:html
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xh:head>
<xf:model xxf:expose-xpath-types="true">
<xf:instance>
<data>
<a/>
<b/>
<c/>
<sum1/>
<sum2/>
</data>
</xf:instance>
<xf:bind ref="a | b | c | sum2" type="xs:decimal"/>
<xf:bind ref="sum1" type="xf:decimal"/>
<xf:bind ref="sum1" calculate="sum((../a, ../b, ../c))"/>
<xf:bind ref="sum2" calculate="sum((../a, ../b, ../c)[string() castable as xs:decimal], 0.0)"/>
</xf:model>
</xh:head>
<xh:body>
<xf:input ref="a"/>
<xf:input ref="b"/>
<xf:input ref="c"/>
<xf:output ref="sum1"><xf:label>Sum only if all values are correct:</xf:label></xf:output>
<xf:output ref="sum2"><xf:label>Sum all correct values and ignore others:</xf:label></xf:output>
</xh:body>
</xh:html>
@dmccreary

This comment has been minimized.

Copy link

commented Aug 29, 2013

Nice example of using a predicate to check the validity of inputs in a calculation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.