XSLTforms/xforms在重复部分中上下移动元素



我使用XSLTforms来呈现XForms。我有一个表单,可以动态地将元素分组到不同的重复组中(客户端希望以这种方式为UI目的对元素进行分组)。这两组元素都是同一父元素的子元素,父元素也可以重复。我希望能够上下移动元素重复组,这对第一个重复组有效,但对第二个重复组无效组。从本质上讲,我需要能够获得父元素中当前项的位置,但是repeat索引似乎只对当前repeat操作。

简化代码:

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms">
<head>
<xf:model id="m-mss">
<xf:instance id="i-rec">
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<msIdentifier>
<!-- group a -->
<country>1a</country>
<institution>2a</institution>
<settlement>3a</settlement>
<institution>4a</institution>
<!-- group b -->
<altIdentifier>1b</altIdentifier>
<altIdentifier>2b</altIdentifier>
<altIdentifier>3b</altIdentifier>
<msName>4b</msName>
</msIdentifier>
</TEI>
</xf:instance>
<xf:instance id="i-move">
<data xmlns="">
<tmp/>
</data>
</xf:instance>
<xf:instance id="i-repeatIndex">
<data xmlns="">
<index>1</index>
</data>
</xf:instance>
</xf:model>
</head>
<body>
<h2>Parent Element </h2>
<xf:repeat
ref="instance('i-rec')//descendant::*:msIdentifier[position() = instance('i-repeatIndex')/index]"
id="msIdentifierRepeatLevel1">
<div id="elementGroup" style="margin:12px; padding:12px; border:1px solid #ccc;">
<div>
<h2>location, institution, settlement</h2>
<div>
<xf:repeat id="msIdentifierRepeatLevel11"
ref="./*[contains(local-name(),'country') or contains(local-name(),'settlement') or contains(local-name(),'institution')]">
<div class="btn-group" role="group">
<xf:trigger xmlns="http://www.w3.org/2002/xforms" appearance="minimal"
class="btn controls moveUp inline">
<xf:label>up</xf:label>
<xf:action ev:event="DOMActivate">
<setvalue ref="instance('i-move')/tmp"
value="index('msIdentifierRepeatLevel11')"/>
<insert
origin="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*[index('msIdentifierRepeatLevel11')]"
nodeset="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*"
at="index('msIdentifierRepeatLevel11') - 1" position="before"/>
<delete
nodeset="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*[instance('i-move')/tmp + 1]"
/>
</xf:action>
</xf:trigger> | <xf:trigger xmlns="http://www.w3.org/2002/xforms"
appearance="minimal" class="btn controls moveDown inline">
<xf:label>down</xf:label>
<xf:action ev:event="DOMActivate">
<setvalue ref="instance('i-move')/tmp"
value="index('msIdentifierRepeatLevel1')"/>
<insert
origin="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*[index('msIdentifierRepeatLevel11')]"
nodeset="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*"
at="index('msIdentifierRepeatLevel11') + 1" position="after"/>
<delete nodeset="."/>
</xf:action>
</xf:trigger> | <span class="elementLabel"><xf:output value="local-name()"
class="elementLabel"/></span>
</div>
<span class="element">
<xf:input class="elementInput" ref="."/>
</span>
</xf:repeat>
</div>
</div>
</div>
<div id="elementGroup2" style="margin:12px; padding:12px; border:1px solid #ccc;">
<div>
<h2>altIdentifier, msName</h2>
<div>
<xf:repeat id="msIdentifierRepeatLevel12"
ref="./*[contains(local-name(),'altIdentifier') or contains(local-name(),'msName')]">
<div class="btn-group" role="group">
<xf:trigger xmlns="http://www.w3.org/2002/xforms" appearance="minimal"
class="btn controls moveUp inline">
<xf:label>up</xf:label>
<xf:action ev:event="DOMActivate">
<setvalue ref="instance('i-move')/tmp"
value="index('msIdentifierRepeatLevel12')"/>
<insert
origin="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*[index('msIdentifierRepeatLevel12')]"
nodeset="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*"
at="index('msIdentifierRepeatLevel12') - 1" position="before"/>
<delete
nodeset="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*[instance('i-move')/tmp + 1]"
/>
</xf:action>
</xf:trigger> | <xf:trigger xmlns="http://www.w3.org/2002/xforms"
appearance="minimal" class="btn controls moveDown inline">
<xf:label>down</xf:label>
<xf:action ev:event="DOMActivate">
<setvalue ref="instance('i-move')/tmp"
value="index('msIdentifierRepeatLevel12')"/>
<insert
origin="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*[index('msIdentifierRepeatLevel12')]"
nodeset="instance('i-rec')//tei:msIdentifier[position() = instance('i-repeatIndex')/index]/*"
at="index('msIdentifierRepeatLevel12') + 1" position="after"/>
<delete nodeset="."/>
</xf:action>
</xf:trigger> | <span class="elementLabel"><xf:output value="local-name()"
class="elementLabel"/></span>
</div>
<span class="element">
<xf:input class="elementInput" ref="."/>
</span>
</xf:repeat>
</div>
</div>
</div>
</xf:repeat>
</body>
</html>

这个形式是一个更大更复杂的形式的一部分,我试图简化这是尽可能的。如果有人有任何想法,这可能是如何工作的,或者如果它甚至可能是如此有帮助,我已经用尽了想法。

非常感谢!威诺娜

获取当前项目的位置总是可以使用preceding-sibling::轴和count()函数。

不使用变量,这个测试用例可以像这样固定:

<xf:repeat id="msIdentifierRepeatLevel11" ref="tei:country | tei:settlement | tei:institution">
<div class="btn-group" role="group">
<xf:trigger xmlns="http://www.w3.org/2002/xforms" appearance="minimal" class="btn controls moveUp inline">
<xf:label><xf:output value="choose(count(preceding-sibling::*[self::tei:country | self::tei:settlement | self::tei:institution]) != 0, 'up', '--')"/></xf:label>
<xf:action ev:event="DOMActivate" if="count(preceding-sibling::*[self::tei:country | self::tei:settlement | self::tei:institution]) != 0">
<xf:setvalue ref="instance('i-move')/tmp" value="count(context()/preceding-sibling::*[self::tei:country | self::tei:settlement | self::tei:institution][1]/preceding-sibling::*) + 1"/>
<xf:insert origin="." ref="parent::*/*" at="instance('i-move')/tmp" position="before"/>
<xf:delete ref="."/>
</xf:action>
</xf:trigger> | 
<xf:trigger xmlns="http://www.w3.org/2002/xforms" appearance="minimal" class="btn controls moveDown inline">
<xf:label><xf:output value="choose(count(following-sibling::*[self::tei:country | self::tei:settlement | self::tei:institution]) != 0, 'down', '----')"/></xf:label>
<xf:action ev:event="DOMActivate" if="count(following-sibling::*[self::tei:country | self::tei:settlement | self::tei:institution]) != 0">
<xf:setvalue ref="instance('i-move')/tmp" value="count(context()/following-sibling::*[self::tei:country | self::tei:settlement | self::tei:institution][1]/preceding-sibling::*) + 1"/>
<xf:insert origin="." ref="parent::*/*" at="instance('i-move')/tmp" position="after"/>
<xf:delete ref="."/>
</xf:action>
</xf:trigger> | 
<span class="elementLabel"><xf:output value="local-name()" class="elementLabel"/></span>
</div>
<span class="element">
<xf:input class="elementInput" ref="."/>
</span>
</xf:repeat>
...
<xf:repeat id="msIdentifierRepeatLevel12" ref="tei:altIdentifier | tei:msName">
<div class="btn-group" role="group">
<xf:trigger xmlns="http://www.w3.org/2002/xforms" appearance="minimal" class="btn controls moveUp inline">
<xf:label><xf:output value="choose(count(preceding-sibling::*[self::tei:altIdentifier | self::tei:msName]) != 0, 'up', '--')"/></xf:label>
<xf:action ev:event="DOMActivate">
<xf:setvalue ref="instance('i-move')/tmp" value="count(context()/preceding-sibling::*[self::tei:altIdentifier | self::tei:msName][1]/preceding-sibling::*) + 1"/>
<xf:insert origin="." ref="parent::*/*" at="instance('i-move')/tmp" position="before"/>
<xf:delete ref="."/>
</xf:action>
</xf:trigger> | 
<xf:trigger xmlns="http://www.w3.org/2002/xforms" appearance="minimal" class="btn controls moveDown inline">
<xf:label><xf:output value="choose(count(following-sibling::*[self::tei:altIdentifier | self::tei:msName]) != 0, 'down', '----')"/></xf:label>
<xf:action ev:event="DOMActivate">
<xf:setvalue ref="instance('i-move')/tmp" value="count(context()/following-sibling::*[self::tei:altIdentifier | self::tei:msName][1]/preceding-sibling::*) + 1"/>
<xf:insert origin="." ref="parent::*/*" at="instance('i-move')/tmp" position="after"/>
<xf:delete ref="."/>
</xf:action>
</xf:trigger> | 
<span class="elementLabel"><xf:output value="local-name()" class="elementLabel"/></span>
</div>
<span class="element">
<xf:input class="elementInput" ref="."/>
</span>
</xf:repeat>

最新更新