From: <ga...@xm...> - 2007-07-19 13:45:17
|
I need a trigger to create and store a derivative document for each file received by the existdb servlet (1.1 from recent svn) via REST put calls, but there's something not right with my code; all I get is log output from parsing the xquery, with no further diagnostic errors or warnings. The xsl stylesheet is stored in the database; using XQueryTrigger, I call an xquery (src appended below); I spent hours yesterday trying to make this work with various tweaks and permutations but with no success: * I originally tried $local:document thinking it was the root node of the current document; I inserted the variable into the triggersLog.xml output and discovered that in STORE/finish events this variable was empty, but in STORE/prepare events the variable was set, though it would not work as a param in the xmldb:store -- I tried doc($local:documentName) and found it had a value in both event types and could be used to store the /current/ document, but would not work as a parameter to the transform. * one fatal flaw in the code below is the call to store the new document under a dynamically computed collection; when I tested this on the doc($local:documentName) instead of the transform output, it would store that document when given a static path of "/db/bogus.xml" and posted to the "/db" collection, but when I tried the dynamical path (ie replacing '/src/' by '/g2/'), existdb says the collection does not exist and rejects the post the REST interface creates new collections as docs are posted -- is there any way to create these dynamic collections on the fly using xquery? something equivalent to a unix "mkdir -p" command? * I tried to util:log print the result of the transform call, but it always failed; I tried $local:document and doc($local:documentName) in both prepare or finish STORE events. There are no log messages to say why the transform call failed. * when either the xmldb:store or the transform:transform functions fail, there are no diagnostics, the query is simply terminated and nothing is written by the update call on triggersLog.xml. I inserted util:log statements ahead of these lines and find they will print to the WEB-INF/logs/exist.log -- is there some way to get more diagnostics on xquery or trigger progress? the (non-working) xquery script follows ... ============8<============8<============ xquery version "1.0"; declare namespace xmldb="http://exist-db.org/xquery/xmldb"; declare namespace transform="http://exist-db.org/xquery/transform"; declare namespace util="http://exist-db.org/xquery/util"; declare variable $local:triggerEvent external; declare variable $local:eventType external; declare variable $local:collectionName external; declare variable $local:documentName external; declare variable $local:document external; declare variable $local:triggersLogFile { "/db/triggersLog.xml" }; declare variable $local:src { "/src/" }; declare variable $local:g2 { "/g2/" }; declare variable $local:g2Collection { fn:replace($local:collectionName, $local:src, $local:g2) }; declare variable $local:g2Name { fn:replace($local:documentName, $local:src, $local:g2) }; declare variable $local:g2xsl { "xmldb:exist://localhost:8080/xsl/g2.xsl" }; (: /db/xsl/g2.xsl tested via http://localhost:8080/existdb/rest/xsl/g2.xsl :) if (not(doc-available($local:triggersLogFile))) then ( xmldb:store("/db", $local:triggersLogFile, <triggers/>) ) else(), if ($local:eventType = 'finish') then ( xmldb:store( $local:g2Collection, (: can I pre-create this collection? :) $local:g2Name, transform:transform( doc($local:documentName), $local:g2xsl, <parameters/> )), update insert <trigger event="{$local:triggerEvent}" eventType="{$local:eventType}" collectionName="{$local:collectionName}" documentName="{$local:documentName}" >{current-dateTime()}</trigger> into doc($local:triggersLogFile)/triggers ) else () (: fin::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :) ============8<============8<============ -- gary lawrence murphy <ga...@xm...> :: www.xmlteam.com :: sports data integration through open standard sportsml :: |