XForms:绑定的复杂计算

发布于 2025-01-06 18:32:03 字数 932 浏览 1 评论 0原文

我正在寻找为绑定执行复杂计算的可能性。给出了以下实例:

<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

我的问题是我不知道在哪里“放置”这些计算。正如您所看到的,我们需要一个带有变量的循环,这些变量可以在循环周期之间存储一些信息。因此,我评估了以下选项:

  1. xforms:variable 与 xforms:repeat => 结合使用重复内的 xforms:variable 无法写入“外部”范围
  2. xforms:setvalue 与保存临时变量的额外实例相结合,并且 xforms:repeat
  3. 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:

  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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2025-01-13 18:32:03

您可以尝试在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文