XForms:绑定的复杂计算
我正在寻找为绑定执行复杂计算的可能性。给出了以下实例:
<root>
<appointments>
<appointment><date>2012-01-01</date></appointment>
<appointment><date>2012-01-03</date></appointment>
</appointments>
<weeks />
</root>
weeks
节点取决于 appointment
节点:
$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
我的问题是我不知道在哪里“放置”这些计算。正如您所看到的,我们需要一个带有变量的循环,这些变量可以在循环周期之间存储一些信息。因此,我评估了以下选项:
- xforms:variable 与 xforms:repeat => 结合使用重复内的 xforms:variable 无法写入“外部”范围
- xforms:setvalue 与保存临时变量的额外实例相结合,并且 xforms:repeat
- xforms:bind 具有计算属性 =>; xpath 中的 for 循环是可能的,但没有变量
任何建议如何解决这个问题?谢谢你!
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:
- xforms:variable in combination with xforms:repeat => xforms:variable inside a repeat can't write to the "outside" scope
- xforms:setvalue in combination with an extra instance that holds temporary variables and xforms:repeat
- xforms:bind with calculate attribute => for loops in xpath are possible, but no variables
Any advice how to approach this problem? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在 Javascript 中实现在约会节点集发生更改时触发的计算。如果您使用 Orbeon Forms,则可以使用
xxforms:script
扩展名。 Orbeon wiki 有一个 示例,说明如何根据JavaScript 计算。另一种解决方案是完全“外部化”计算并创建一个小型 Web 服务(XQuery?)来返回计算结果。您可以使用
xforms:submit
机制来提供该服务并访问其结果。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.