From cc0305e4e979a36251328faca19f1ddba4165d12 Mon Sep 17 00:00:00 2001 From: Benito van der Zander Date: Wed, 15 Jul 2020 17:27:53 +0200 Subject: [PATCH 1/2] standard XQuery 3.1 --- memory-operations-pure-xquery.xqy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/memory-operations-pure-xquery.xqy b/memory-operations-pure-xquery.xqy index f5b89c0..70d6460 100644 --- a/memory-operations-pure-xquery.xqy +++ b/memory-operations-pure-xquery.xqy @@ -1,4 +1,4 @@ -xquery version "3.0"; +xquery version "3.1"; (:~ Copyright (c) 2016 Ryan Dew @@ -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, @@ -160,7 +160,7 @@ as map(*)? $function-key, $transform-function ) - )) + ), map {"duplicates": "use-last"}) }; (: Select the root to return after transaction :) @@ -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", @@ -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 From 8bbb8f1a0c999b8672671abfc352b3143351fbb6 Mon Sep 17 00:00:00 2001 From: Benito van der Zander Date: Wed, 15 Jul 2020 18:11:45 +0200 Subject: [PATCH 2/2] Update README.md how to use the pure version --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index f453ae9..695f5c2 100644 --- a/README.md +++ b/README.md @@ -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 :)