Avoiding redeclaration for transactions in Xquery -


given:

let $name := '751-1500'     return xdmp:node-delete(doc(concat('/', $name, '.xml'))//foo);  let $name := '751-1500' return xdmp:node-delete(doc(concat('/', $name, '.xml'))//bar);  let $name := '751-1500' return xdmp:node-delete(doc(concat('/', $name, '.xml'))//baz); 

how can avoid having redeclare $name?

using separate transactions i'm not sure there nice way this. can declare variable external. still have declared multiple times, have assign once when called via xdmp:invoke (or xdmp:eval):

declare variable $name xs:string external ; xdmp:node-delete(doc(concat('/', $name, '.xml'))//foo);  declare variable $name xs:string external ;     xdmp:node-delete(doc(concat('/', $name, '.xml'))//bar);  declare variable $name xs:string external ; xdmp:node-delete(doc(concat('/', $name, '.xml'))//baz); 

then can call module multiple times using invoke different values:

xdmp:invoke('delete-nodes.xqy', (xs:qname('name'), '751-1500')), xdmp:invoke('delete-nodes.xqy', (xs:qname('name'), '751-1501')), xdmp:invoke('delete-nodes.xqy', (xs:qname('name'), '751-1502')) 

if don't want module, wrap in function accepts $name param , uses xdmp:eval instead.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -