Op 19-02-2020 om 12:08 schreef Ben Engbers:
Hi,
I have a database that contains several thousand records with elements that I will never need so I want to remove them. The following code snippet returns the expected element:
I tried to use update:apply to update the database but when I execute the following function, I get this message: [XPDY0002] element(functx:remove-elements): Context is undeclared
---------------
import module namespace functx = 'http://www.functx.com'; declare %updating function local:clean_verbs( $old as node(), $rem as xs:string* ) as empty-sequence() { update:apply(functx:remove-elements, [$old, $rem]) };
let $p := collection("TextMining/nl-verbs.csv")/csv/record[1] let $remove := ("onbekend1", "onbekend2", "onbekend3", "onbekend4")
return local:clean_verbs($p, $remove)
----------------------
I have two questions: 1: If I want to use the update module, how should I provide the context to the query? 2: How can I update all records without making use of update:apply or update:for-each (what is the befit of the update-module)?
With this code, I managed to replace all records: ---------- import module namespace functx = 'http://www.functx.com';
let $old := collection("TextMining/nl-verbs.csv")/csv/record let $remove := ("onbekend1", "onbekend2", "onbekend3", "onbekend4")
for $o in $old return replace node $o with functx:remove-elements($o, $remove) -----------
Remains my questions: 1: How can I achieve the same task, using functx:remove-elements and update:for-each? 2: What's the benefit of using the update module?
Cheers, Ben