使用带迭代的 xf:setvalue 函数时如何引用位置 [英] How to refer to position when using xf:setvalue function with iterate
问题描述
Considering this code example and this post
...
<xf:action>
<xf:setvalue
iterate="instance('fr-send-submission-params')/@*"
ref="."
value="event(name(context()))"/>
</xf:action>
...
如何引用当前的迭代位置?喜欢 value="position()"
How can refer to current iterated position? Like value="position()"
我可以将此位置用作 xpath 表达式的变量吗?喜欢 ref="/AnotherElement[position()]"
Can i use this position as variable to xpath expressions? Like ref="/AnotherElement[position()]"
推荐答案
以下作品:
<xf:action iterate="instance('fr-send-submission-params')/@*">
<xf:var name="p" value="position()"/>
<xf:setvalue ref="." value="$p"/>
</xf:action>
我认为你不能只使用 xf:setvalue
,因为 ref
将表达式的计算上下文更改为单个项目,这意味着 position()
在 value
内返回 1
.
I don't think you can get away just with xf:setvalue
, because ref
changes the evaluation context of the expression to a single item which means that position()
returns 1
within value
.
我看到您对属性进行迭代的警告:我认为不能保证属性位置是一致的.
A warning as I see that you iterate on attributes: I don't think that attribute position is guaranteed to be consistent.
更新:
如果您有元素,则以下内容有效,但是您需要了解 xf:setvalue
中迭代的项目:
The following works if you have elements, but then you need to have knowledge of the items iterated within the xf:setvalue
:
<xf:setvalue
event="DOMActivate"
iterate="value"
ref="."
value="count(preceding-sibling::value) + 1"/>
所以我认为带有封闭操作的选项要清晰得多.
So I think that the option with an enclosing action is much clearer.
这篇关于使用带迭代的 xf:setvalue 函数时如何引用位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!