How to refer to position when using xf:setvalue fu

2019-09-06 18:41发布

Considering this code example and this post

...
<xf:action>
<xf:setvalue
            iterate="instance('fr-send-submission-params')/@*"
            ref="."
            value="event(name(context()))"/>
</xf:action>
...

How can refer to current iterated position? Like value="position()"

Can i use this position as variable to xpath expressions? Like ref="/AnotherElement[position()]"

1条回答
叼着烟拽天下
2楼-- · 2019-09-06 19:25

The following works:

<xf:action iterate="instance('fr-send-submission-params')/@*">
    <xf:var name="p" value="position()"/>
    <xf:setvalue ref="." value="$p"/>
</xf:action>

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.

Update:

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.

查看更多
登录 后发表回答