I am looking for a possibility to perform complex calculations for a binding. The following instance is given:
<root>
<appointments>
<appointment><date>2012-01-01</date></appointment>
<appointment><date>2012-01-03</date></appointment>
</appointments>
<weeks />
</root>
The weeks
node depends on the appointment
nodes:
$weeks = 0
$week_begin = xs:date("1970-01-01")
for $appointment in //appointments/appoinment
if # Check if $appointment is in new week
$weeks = $weeks + 1
$week_begin = # Do some more calculationx
My problem is that I don't know where to "put" those calculations. As you can see we need a loop with variables that can store some information between loop cycles. Therefore, I have evaluated the following options:
Any advice how to approach this problem? Thank you!
You could try to implement the calculation in Javascript that's triggered if the appointments nodeset has changed. If you're using Orbeon Forms, you could use the xxforms:script
extension. The Orbeon wiki has an example how to set an instance value based on a javascript calculation.
Another solution would be to completely "externalise" the calculation and to create a little web service (XQuery?) that would return the result of the calculation. You could use the xforms:submit
mechanism to feed that service and access its result.