XQuery Update Facility: insert as first vs. insert as last

There seems to be something odd in the specification of insert in
Section 2.3 of the XQuery Update Facility WD. According to 4.a "insert
as last" is compiled into update primitives of the form
"upd:insertIntoAsLast", while "insert as first" does not have a
designated update primitive.

Consider the following input bound to a variable $x := <a><b/></a> 
If I'm not mistaken, the XQuery expression 
  insert <c/> into $x as first, insert <d/> before $x/b 
signals an incompatibility, while the expression
  insert <c/> into $x as last, insert <d/> after $x/b 
does not. The reasoning for this conclusion is as follows. Suppose n_a,
n_b, n_c and n_d are the nodes that correspond to the nodes with the
corresponding tag name. The first expression yields the following
pending update list:
  { upd:insertBefore(n_b, n_c), upd:insertBefore(n_b, n_d) }
The second expression yields the following pending update list:
  { upd:insertIntoAsLast(n_a, n_c), upd:insertAfter(n_b, n_d) }
According to the compatibility matrix, the first pending update list
contains a conflict, while the second doesn't. The result of the second
expression is <a><b/><d/><c/></a> (no matter in which order the two
primitives are evaluated).

I don't think that this asymmetry is desired and see two ways to solve
this issue:
(1) Add an upd:insertAsFirst primitive.
(2) If "as last" is specified in an insert statement, do something
similar to "as first" when there is a child, i.e., insert after the last
child node. When there are no children, perform upd:insertInto. This
would remove the need for an upd:insertAsLast primitive, but would cause
the second expression to signal a conflict.

Roel

Received on Thursday, 9 March 2006 09:02:01 UTC