-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node Updates: Functions #1702
Comments
Yes, I think it would be a good idea to progress this. Note that the semantics could also be described in terms of XSLT equivalents, which avoids relying on a spec that isn't fully defined in an XQuery 4.0 context. (Or, perhaps a bit more laboriously, in terms of recursive XQuery functions using typeswitch). I'm not sure what you gain by supplying the target of rename/delete etc as a function rather than just a list of nodes. Why
rather than
And if we're doing update through functions, I think it would make sense to provide node construction through functions as well: see #573 |
I have learned to appreciate XQuery Update over time, so I think we will benefit a lot if we target a solution that can be expressed as a subset of XQuery Update as much as possible. Otherwise, multiple solutions would exist in parallel, and it will be difficult to argue which solution is the one to prefer in XQuery. Next, it should be simple to switch between both worlds, and for example enhance an XQuery 4.0 function call to an XQuery Update expression if it turns out that the function call is too limited. But in principle I agree: If we manage to define functionality that is simple enough to work out without XQUF references, it would simplify things a lot.
From the XQUF perspective, it is certainly the more obvious way to specify it. It would be much harder to specify an equivalent XQUF expression with list of target nodes that is generated before the node is copied. If we supply a list of nodes instead of a function, we:
Next, if we supply a list of nodes, things get challenging with nested target nodes. Imagine we wanted to rename nested (: expected: <xml><b><b><b/></b></b></xml> :)
let $xml := <xml><a><a><a/></a></a></xml>
return $xml transform with { rename node .//a as 'b' } With the following recursive XQuery code… declare function update:rename(
$node as element(),
$target as node()*,
$name as xs:QName
) as node() {
element { node-name($node) } {
for $child in $node/*
return if(some $t in $target satisfies $t is $child) then (
element { $name } { $child }
) else (
$child
) ! update:rename(., $target, $name)
}
}; …the uppermost replaced element In principle, the approach resembles the first proposal for map/arrray updates (#832). In both cases, we could probably get rid of the function notation as long as we can be sure that we can always create a relationship between the copied and the target items. |
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: