W3C home > Mailing lists > Public > public-xformsusers@w3.org > April 2019

Re: inserting into an empty list

From: Steven Pemberton <steven.pemberton@cwi.nl>
Date: Wed, 03 Apr 2019 22:26:56 +0200
To: public-xformsusers@w3.org
Message-ID: <op.zzotq6qusmjzpq@steven-xps>
So the answer is:

5 4 3 2 1
1 2 3 4 5

and it is the first line that surprised me initially.

The instance ends up looking like this:
    <data xmlns="">
       <v>5</v><v>4</v><v>3</v><v>2</v><v>1</v>
       <list>
          <v>1</v><v>2</v><v>3</v><v>4</v><v>5</v>
       </list>
    </data>

The reason is this. In  
https://www.w3.org/community/xformsusers/wiki/XForms_2.0#The_insert_Element

[[[[
The target location is determined for each cloned node:
* if the target-sequence is non-empty, then the cloned node will become  
the sibling of the insert location node:
   [...] the target location is immediately before or after the insert  
location node, depending on the position attribute setting or its default;
* if the target-sequence is empty, then the cloned node will become a  
child of the insert location node.
   The target location is determined by the type of the insert location  
node:
   [...]
   * an element:
     [...] the target location is before the first child of the insert  
location node, or the child list of the insert location node if it is  
empty;
]]]]

So if the target-sequence is non-empty, it is inserted depending on @at  
and @position, and if neither of those are present, *after* the *last*  
node.
If the target-sequence is empty, it is inserted (regardless of @at and  
@position, which have no effect) *before* the *first* node.

So that means repeated inserting
* in a non-empty list inserts in insertion order;
* in an empty-list inserts in reverse insertion order.

It is an edge case I agree, since in the normal use-case the first insert  
will make the list non-empty, and you won't see the effect.
But it is a strange inconsistency.

Another example:

	    <insert context="list" ref="n" origin="instance('s')/v[1]"/>
	    <insert context="list" ref="n" origin="instance('s')/v[2]"/>
	    <insert context="list" ref="n" origin="instance('s')/v[3]"/>
	    <insert context="list" ref="n" origin="instance('s')/v[4]"/>
	    <insert context="list" ref="n" origin="instance('s')/v[5]"/>

	    <insert context="list" ref="v" origin="instance('s')/v[1]"/>
	    <insert context="list" ref="v" origin="instance('s')/v[2]"/>
	    <insert context="list" ref="v" origin="instance('s')/v[3]"/>
	    <insert context="list" ref="v" origin="instance('s')/v[4]"/>
	    <insert context="list" ref="v" origin="instance('s')/v[5]"/>

would give

       <list>
          <v>5</v><v>4</v><v>3</v><v>2</v><v>1</v>
          <v>1</v><v>2</v><v>3</v><v>4</v><v>5</v>
       </list>

Steven

On Wed, 03 Apr 2019 14:24:35 +0200, Steven Pemberton  
<steven.pemberton@cwi.nl> wrote:

> What does this output? (Answer supplied in a following mail: but it  
> caught me out!).
>
>        <model>
> 	 <instance>
> 	    <data xmlns="">
> 	       <list/>
> 	    </data>
> 	 </instance>
> 	 <instance id="s">
> 	    <data xmlns="">
> 	       <v>1</v>
> 	       <v>2</v>
> 	       <v>3</v>
> 	       <v>4</v>
> 	       <v>5</v>
> 	    </data>
> 	 </instance>
> 	 <action ev:event="xforms-ready">
> 	    <insert ref="list/v" origin="instance('s')/v[1]"/>
> 	    <insert ref="list/v" origin="instance('s')/v[2]"/>
> 	    <insert ref="list/v" origin="instance('s')/v[3]"/>
> 	    <insert ref="list/v" origin="instance('s')/v[4]"/>
> 	    <insert ref="list/v" origin="instance('s')/v[5]"/>
> 	    <insert context="list" ref="v" origin="instance('s')/v[1]"/>
> 	    <insert context="list" ref="v" origin="instance('s')/v[2]"/>
> 	    <insert context="list" ref="v" origin="instance('s')/v[3]"/>
> 	    <insert context="list" ref="v" origin="instance('s')/v[4]"/>
> 	    <insert context="list" ref="v" origin="instance('s')/v[5]"/>
> 	 </action>
>        </model>
>        <group>
> 	 <repeat ref="v"     ><output value="."/></repeat>
> 	 <repeat ref="list/v"><output value="."/></repeat>
>        </group>
>
> Steven
Received on Wednesday, 3 April 2019 20:27:21 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 3 April 2019 20:27:22 UTC