Sure! My existdb version is 2.2.
xquery version "3.0";
declare boundary-space preserve;
declare namespace exist = "http://exist.sourceforge.net/NS/exist";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace xmldb="http://exist-db.org/xquery/xmldb";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "text";
declare option output:indent "yes";
import module namespace file="http://exist-db.org/xquery/file";
let $log-in := xmldb:login("/db", "admin", "admin")
for $k in (35,36,37)
let $AppletName := fn:doc(fn:concat('/db/project/AppletA_',$k,'.xml'))//APPLET/@NAME/string()
let $collection := fn:concat('xmldb:exist:/db/project/Scripts_',$k)
let $node :=(<APPLET_SCRIPTS>{
for $i in fn:doc(fn:concat('/db/project/AppletA_',$k,'.xml'))//APPLET_SERVER_SCRIPT
let $MethodName := $i/@NAME
let $MethodScript := string($i/@SCRIPT)
let $file-name := fn:concat($MethodName,'.js')
let $store := xmldb:store($collection,$file-name, $MethodScript)
return <div>{$MethodScript}</div>
}</APPLET_SCRIPTS>)
return $node
A fragment of xml is:
screenshot xml fragment
The content of file created is this one line string:
function Prova() { try { var sVal = TheApplication().InvokeMethod("LookupValue","FS_ACTIVITY_CLASS","CIM_FAC18"); var recordFound = searchRecord(sVal); if(!recordFound) { this.InvokeMethod("NewRecordCustom"); this.BusComp().SetFieldValue("Class",sVal); this.BusComp().WriteRecord(); } } catch(e) { throw(e); } finally { sVal = null; } }