Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ return
:)
```

## Pure XQuery 3.1

Using pure, standard XQuery 3.1, the above examples can be written as

```xquery
import module namespace mem-op = "http://maxdewpoint.blogspot.com/memory-operations" at "memory-operations-pure-xquery.xqy";
mem-op:copy(fn:root($file))
=> mem-op:replace($file/title, element title {"my new title"})
=> mem-op:insert-child($file, attribute new-attribute {"my new attribute"})
=> mem-op:execute()
```

and

```xquery
import module namespace mem-op = "http://maxdewpoint.blogspot.com/memory-operations" at "memory-operations-pure-xquery.xqy";
let $oldx := /a/b/x
return
($oldx,
mem-op:copy($oldx)
=> mem-op:rename($oldx, fn:QName("","newx"))
=> mem-op:replace-value($oldx, $oldx * 5)
=> mem-op:execute()
)
```


## Other Operations
```xquery
(: See http://www.w3.org/TR/xquery-update-10/#id-delete :)
Expand Down
10 changes: 5 additions & 5 deletions memory-operations-pure-xquery.xqy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
xquery version "3.0";
xquery version "3.1";

(:~
Copyright (c) 2016 Ryan Dew
Expand Down Expand Up @@ -149,7 +149,7 @@ as map(*)?
{
let $function-key as xs:string := mem-op:function-key($transform-function)
return
map:new((
map:merge((
mem-op:queue(
$transaction-map,
$nodes-to-change,
Expand All @@ -160,7 +160,7 @@ as map(*)?
$function-key,
$transform-function
)
))
), map {"duplicates": "use-last"})
};

(: Select the root to return after transaction :)
Expand Down Expand Up @@ -206,7 +206,7 @@ as map(*)
return
(
mem-op:all-nodes-from-same-doc($nodes-to-modify,map:get($transaction-map,"copy")),
map:new((
map:merge((
$transaction-map,
map:entry(
"operation",
Expand Down Expand Up @@ -234,7 +234,7 @@ as map(*)
(: Ensure nodes to modifier nodes are accummulated :)
map:get($transaction-map, "modifier-nodes"))
)
))
), map {"duplicates": "use-last"})
)
else
$transaction-map
Expand Down