Hi Winona,
XPath axes usage is a possibility for such a complex test case.
First, the self:: axis can be used to reduce the size of XPath expressions testing lists of node names.
XForms, as XSLT, is always providing a context node for XPath evaluation. Using the parent:: axis is interesting for smaller and more general expressions.
In this test case, the preceding-sibling:: and following-sibling:: axes will allow to calculate the position of an item within its own editing group so it can be moved up or down.
It is also interesting to be able to disable out-of-bounds moves for the first and the last items (XForms 2.0 does not yet specify that @readonly can also be added to an input control...).
Please find the proposed fixed form attached.
Using variables would also simplify again the form but they will be more widely supported in XSLTForms in the next release. Which one are you using now?
Thank you for your feedback!
--Alain
Le 10/01/2023 15:29 CET, Winona Salesky <[email protected]> a écrit :Hi All,_______________________________________________ Xsltforms-support mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/xsltforms-supportI have a form that dynamically groups elements into different repeat groups (client wants to group the elements in this way for UI purposes). The two groups of elements are all children of the same parent element, which can also repeat. I want to be able to move elements up and down within the repeat groups, this works for the first repeat group, but not for second group.This form is part of a larger more complex form, I have tried to simplify it is much as possible.If anyone has any ideas how this might work, or if it is even possible that would be so helpful, I have run out of ideas.Thanks so much!-Winona
<?xml-stylesheet href="xsl/xsltforms.xsl" type="text/xsl"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xf="http://www.w3.org/2002/xforms"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta charset="utf-8"/> <title>Bug Demo</title> <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 class="h3 mainElement">Identification </h2> <xf:repeat ref="instance('i-rec')//tei: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="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> </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="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" if="count(preceding-sibling::*[self::tei:altIdentifier | self::tei:msName]) != 0"> <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" if="count(following-sibling::*[self::tei:altIdentifier | self::tei:msName]) != 0"> <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> </div> </div> </div> </xf:repeat> </body> </html>
_______________________________________________ Xsltforms-support mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/xsltforms-support
