You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #1225, I have summarized some thoughts on generalizing updates for both nodes and structured items (maps/arrays).
XQuery Update is complex, as updates are in general, so we may still decide that it is too ambitious to introduce update features in the core language. If we want to give it a try, we could offer functions that are based on XQUF, but that only perform one update operation at a a time on a given input. This way, we could ignore the sophisticated Pending Update List semantics, which is only important when multiple updating expressions are specified and need to be checked and brought into order.
A function set that provides an equivalent functionality for all XQUF update operations could look as follows (the presented functions are valid XQuery Update code):
declarenamespace update = 'http://www.w3.org/TR/xquery-update';
declarefunctionupdate:delete(
$node asnode(),
$path asfn(node()) asnode()*
) asnode() {
copy $c := $node
modifydeletenode $path($c)
return $c
};
declarefunctionupdate:rename(
$node asnode(),
$path asfn(node()) asnode()*,
$name as (xs:QName | xs:NCName | fn(node(), xs:integer) as (xs:QName | xs:NCName))
) asnode() {
copy $c := $node
modify (
for $target at $pos in $path($c)
let $result := if($name instanceoffn(*)) {
$name($target, $pos)
} else {
$name
}
returnrenamenode $target as $result
)
return $c
};
declarefunctionupdate:replace(
$node asnode(),
$path asfn(node()) asnode()*,
$contents as (node() | xs:anyAtomicType | fn(node(), xs:integer) asnode()*)*,
$options asrecord(value? as xs:boolean)? := {}
) asnode() {
copy $c := $node
modify (
for $target at $pos in $path($c)
let $result := (
for $content in $contents
returnif($content instanceoffn(*)) {
$content($target, $pos)
} else {
$content
}
)
returnif($options?value) {
replacevalueofnode $target with $result
} else {
replacenode $target with $result
}
)
return $c
};
declarefunctionupdate:insert(
$node asnode(),
$path asfn(node()) asnode()*,
$contents as (node() | xs:anyAtomicType | fn(node(), xs:integer) as (node() | xs:anyAtomicType))*,
$options asrecord(position? asenum('last', 'first', 'before', 'after'))? := {}
) asnode() {
copy $c := $node
modify (
for $target at $pos in $path($c)
let $result := (
for $content in $contents
returnif($content instanceoffn(*)) {
$content($target, $pos)
} else {
$content
}
)
returnswitch($options?position) {
case'before'returninsertnode $result before $target
case'after'returninsertnode $result after $target
case'first'returninsertnode $result asfirstinto $target
defaultreturninsertnode $result aslastinto $target
}
)
return $c
};
Here are some exemplary function calls:
let $node := <xml><e/><e/></xml>
return (
(: deletes all <e/> child nodes :)update:delete($node, fn { e }),
(: renames the <e/> child nodes to <f/> :)update:rename($node, fn { e }, 'f'),
(: replaces the <e/> child nodes with <replaced/> :)update:replace($node, fn { e }, <replaced/>),
(: replaces the string value of the <e/> child nodes with 'text' :)update:replace($node, fn { e }, 'text', { 'value': true() }),
(: inserts a 'text' text node into the <e/> child nodes :)update:insert($node, fn { e }, 'text'),
(: inserts 'text1' and 'text2' text nodes into the <e/> child nodes :)update:insert($node, fn { e }, fn($node, $pos) { 'text' || $pos }),
(: inserts an <x/> element after each <e/> child node :)update:insert($node, fn { e }, <x/>, { 'position': 'after' })
)
Multiple update operations can easily be chained:
(: rename <e/> child nodes to <f/>, insert 'x' text nodes :)
<xml><e/><e/></xml>
=> update:rename(fn { e }, 'f')
=> update:insert(fn { f }, 'x')
Ideally, we could offer a similar function set (or maybe even the same) for maps and arrays in a next step (see #77). The map/array syntax would be similar for deletions…
…but it certainly gets trickier for other operations.
If some of you believe that the presented approach is something that we should pursue, I will be happy to add details. As an alternative, we could pursue the XQUF light approach that I have sketched in #1225, based on the existing XQUF update keywords.
Yet another solution could be to stick with what we have, but add map/array update features to XQUF.
The text was updated successfully, but these errors were encountered:
In #1225, I have summarized some thoughts on generalizing updates for both nodes and structured items (maps/arrays).
XQuery Update is complex, as updates are in general, so we may still decide that it is too ambitious to introduce update features in the core language. If we want to give it a try, we could offer functions that are based on XQUF, but that only perform one update operation at a a time on a given input. This way, we could ignore the sophisticated Pending Update List semantics, which is only important when multiple updating expressions are specified and need to be checked and brought into order.
A function set that provides an equivalent functionality for all XQUF update operations could look as follows (the presented functions are valid XQuery Update code):
Here are some exemplary function calls:
Multiple update operations can easily be chained:
Ideally, we could offer a similar function set (or maybe even the same) for maps and arrays in a next step (see #77). The map/array syntax would be similar for deletions…
…but it certainly gets trickier for other operations.
If some of you believe that the presented approach is something that we should pursue, I will be happy to add details. As an alternative, we could pursue the XQUF light approach that I have sketched in #1225, based on the existing XQUF update keywords.
Yet another solution could be to stick with what we have, but add map/array update features to XQUF.
The text was updated successfully, but these errors were encountered: