Database Reference
In-Depth Information
Parameter
Description
Mandatory/optional
If you wish to pass any parameters as external variables into your XQuery, you
need to declare the prefix of the namespace (declared in your XQuery) that they
should be bound to.
Mandatory if passing
parameters to external
variables
bindingPre
fix
You may pass any other parameter to your XQuery and it will be bound to the
equivalently named external variable (in the namespace indicated by binding
Prefix ), which is declared in your XQuery.
Optional
anything
You will find an example of a simple XQuery trigger implemented in an XQuery
library module in the file chapters/advanced-topics/simple-example-trigger.xqm of the
book-code Git repository (see “Getting the Source Code” on page 15 ), and in
Example 16-10 . The trigger simply writes an entry to eXist's logfile to record the fact
that the trigger function was called when a new document was stored into a collec‐
tion in the database.
Example 16-10. Simple XQuery trigger implemented in an XQuery library module
module namespace et = "http://example/trigger" ;
declare namespace trigger = "http://exist-db.org/xquery/trigger" ;
import module namespace util = "http://exist-db.org/xquery/util" ;
declare variable $ et:log-level external ;
declare function trigger:after-create-document ( $ uri as xs:anyURI ) {
et:log (( "XQuery Trigger called after document '" , $ uri , "' created." ))
};
declare function et:log ( $ msgs as xs:string + ) {
util:log ( $ et:log-level , $ msgs )
};
Namespace binding prefix of the XQuery library module.
Import of the XQuery trigger namespace, so that you may implement trigger
functions in this namespace.
External variable will be bound to a parameter named log-level declared in the
trigger configuration within the collection configuration document.
Your implementation of the after-create-document function. This must be in
the trigger namespace!
Call to your module's functions that provide the actual processing.
 
Search WWH ::




Custom Search