W3C home > Mailing lists > Public > public-qt-comments@w3.org > September 2006

[UPDATE] Propose consistent semantics for target expressions

From: Sudanagunta, Vas <Vas.Sudanagunta@dig.com>
Date: Fri, 8 Sep 2006 15:56:43 -0700
Message-Id: <79BBAF864AA26147A2AA82690985BFB307451BAE@sm-cala-xm20.swna.wdpr.disney.com>
To: <public-qt-comments@w3.org>
Hello,

 

I'd like to suggest a change to the syntax of Insert expressions. 

 

Current Insert expression syntax
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#id-insert>  seems less
than ideal as the target expression sometimes does not represent the
node that will actually be modified. This is anomalous among updating
expressions. It is even inconsistent with the insert into versions of
the Insert expression.

 

Below is a modified syntax for Insert Expression that has consistent
semantics for the target expression. Functionality is unchanged.  I am
not an expert in grammar design; there may be a better syntax than this.
Neither am I an expert in the XQuery grammar - so I'm sure there are
flaws in the way I represent my proposed changes.

 

Inserts or modified sections are highlighted, though deletions are
sometimes emphasized with red strikeout.

 

Vas Sudanagunta

Walt Disney Internet Group

 


2.3.1 Insert

[142]   

InsertExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#prod-xquery-InsertExpr>


   ::=   

"do" "insert" SourceExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-SourceExpr>
"into" TargetExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-TargetExpr>
(

  ("as" ("first" | "last"))

| ("after" SiblingExpr)
| ("before" SiblingExpr) 

)?

[146]   

SourceExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#prod-xquery-SourceExpr>


   ::=   

ExprSingle
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-ExprSingle> 

[147]   

TargetExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#prod-xquery-TargetExpr>


   ::=   

ExprSingle
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-ExprSingle> 

 

SiblingExpr

   ::=   

ExprSingle
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-ExprSingle> 

An insert expression inserts copies of one or more nodes as children of
a designated node in an XDM instance
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-xdm-instance>  at a
designated position. If a position is not designated, the position of
the inserted nodes within the designated parent is
implementation-dependent. An insert expression is an updating expression
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-updating-expression>
..

Examples:

*         Insert a year element after the publisher of the first book.

do insert <year>2005</year>
    into fn:doc("bib.xml")/books/book[1]/publisher after "publisher"

*         Navigating by means of several bound variables, insert a new
police report into the list of police reports for a particular accident.

do insert $new-police-report
   as last into fn:doc("insurance.xml")/policies
      /policy[id = $pid]
      /driver[license = $license]
      /accident[date = $accdate]
      /police-reports
 as last

The semantics of an insert expression are as follows:

1.      SourceExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-SourceExpr>
must not be an updating expression
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-updating-expression>
; otherwise a static error is raised [err:XUST0101
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#ERRXUST0101> ].
SourceExpr
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#doc-xquery-SourceExpr>
is evaluated as though it were an enclosed expression in an element
constructor (see Rule 1e in Section 3.7.1.3 of [XQuery 1.0]
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#xquery> ). The result
of this step is either an error or a sequence of nodes to be inserted,
called the insertion sequence. If the insertion sequence contains a
document node, the document node is replaced in the insertion sequence
by its children. If the insertion sequence contains an attribute node
following a node that is not an attribute node, a type error is raised
[err:TBD]. Let $alist be the sequence of attribute nodes in the
insertion sequence. Let $clist be the remainder of the insertion
sequence, in its original order.

2.      The target expression must not be an updating expression
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-updating-expression>
; otherwise a static error is raised [err:XUST0101
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#ERRXUST0101> ]. The
target expression is evaluated. If into is specified, tThe result must
be a single element node or a single document node; otherwise a type
error is raised [err:TBD]. If before or after is specified, the result
must be a single element node whose parent property is not empty;
otherwise a dynamic error is raised [err:TBD]. Let $target be the node
returned by the target expression.

3.      SiblingExpr must not be an updating expression
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-updating-expression>
; otherwise a static error is raised [err:XUST0101
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#ERRXUST0101> ].
SiblingExpr is evaluated as though it were the name expression of a
computed element constructor (see Section 3.7.3.1 of [XQuery 1.0]
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#xquery> .)  The result
is either an error or an expanded QName. TargetExpr/$QName must evaluate
to a single node; otherwise a dynamic error is raised [err:TBD]. Let
$sibling be this node.  

4.      The result of the insert expression is a pending update list
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-pending-update-list>
constructed as follows:

1.      If as first is specified and $target has at least one child, let
$child be the first child node of $target. The pending update list
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-pending-update-list>
consists of the following update primitives
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-update-primitive> :

1.      If $alist is not empty, upd:insertAttributes($target, $alist)

2.      If $clist is not empty, upd:insertBefore($child, $clist)

2.      If as last is specified, or as first is specified and $target
has no children, the pending update list
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-pending-update-list>
consists of the following update primitives
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-update-primitive> :

1.      If $alist is not empty, upd:insertAttributes($target, $alist)

2.      If $clist is not empty, upd:insertIntoAsLast($target, $clist)

3.      If into is specified and neither as first nor as last nor after
nor before is specified, the pending update list
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-pending-update-list>
consists of the following update primitives
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-update-primitive> :

1.      If $alist is not empty, upd:insertAttributes($target, $alist)

2.      If $clist is not empty, upd:insertInto($target, $clist)

4.      If before is specified, let $parent be the parent node of
$target. Tthe pending update list
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-pending-update-list>
consists of the following update primitives
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-update-primitive> :

1.      If $alist is not empty, upd:insertAttributes($target, $alist)

2.      If $clist is not empty, upd:insertBefore($sibling, $clist)

5.      If after is specified, let $parent be the parent node of
$target. TThe pending update list
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-pending-update-list>
consists of the following update primitives
<http://www.w3.org/TR/2006/WD-xqupdate-20060508/#dt-update-primitive> :

1.      If $alist is not empty, upd:insertAttributes($target, $alist)

2.      If $clist is not empty, upd:insertAfter($sibling, $clist)


 


 


 


 

                  

 
Received on Saturday, 9 September 2006 17:52:43 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:57:14 UTC