Structural constraints

I just want to plant a seed in your heads.

There are occasions where I want to create a structure of a certain size,  
that may change during execution.

Let's say I have a value 'size' that changes during execution, and I must  
make sure that there are that many elements in my structure at all times.

At present, I do it like this:

 <instance>
    <data xmlns="">
       <size>10</size>
       <element/>
    </data>
 </instance>

 <action ev:event="xforms-ready">
     <insert ref="element" while="count(element) &lt; size"/>
 </action>

Then at start up I have the right number of elements.

However, if size changes, I have to update the number of elements. The  
only way to do that is to have an invisible control, and catch value  
changed events there:

 <output ref="size" class="invisible">
    <action ev:event="xforms-value-changed">
       <insert ref="element" while="count(element) &lt; size"/>
       <delete ref="element[last()]" while="count(element) &gt; size"/>
    </action>
 </output>

(an alternative to doing the deletes is to use relevance:

 <bind ref="element" relevant="position() &lt; ../size"/>

which saves repeated insertions and deletions if size changes a lot).

Now all this work is incredibly related to rebuild(). A value changes, the  
model responds.

Here is a strawman, just to kick off the thought process:

 <bind ref="element" count="../size"/>

And a possible addition:

 <bind ref="element" count="../size"  
origin="instance('template')/element"/>

Steven

Received on Wednesday, 2 May 2018 10:32:26 UTC