Skip to content

Instantly share code, notes, and snippets.

@ebruchez
Last active December 21, 2015 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebruchez/6234199 to your computer and use it in GitHub Desktop.
Save ebruchez/6234199 to your computer and use it in GitHub Desktop.
<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
Copy link

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