How to refer to position when using xf:setvalue function with iterate

◇◆丶佛笑我妖孽 提交于 2020-01-06 14:08:14

问题


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:


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.



来源:https://stackoverflow.com/questions/29512690/how-to-refer-to-position-when-using-xfsetvalue-function-with-iterate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!