3

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:

  1. xforms:variable in combination with xforms:repeat => xforms:variable inside a repeat can't write to the "outside" scope
  2. xforms:setvalue in combination with an extra instance that holds temporary variables and xforms:repeat
  3. xforms:bind with calculate attribute => for loops in xpath are possible, but no variables

Any advice how to approach this problem? Thank you!

Jayy
  • 2,368
  • 4
  • 24
  • 35
lacco
  • 882
  • 1
  • 10
  • 24
  • Can you give me one example of such complex calculations. Above given example is kind of incomplete. – Jayy Feb 17 '12 at 14:50
  • I have some Ruby code that might make the "algorithm" more conrete... https://gist.github.com/c3bf9d7948a538b5bbd0 – lacco Feb 17 '12 at 16:33

1 Answers1

2

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.

tohuwawohu
  • 13,268
  • 4
  • 42
  • 61