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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -