[oXygen-user] Preprocessing Xquery

Paul Ryan
Mon Jan 12 12:42:38 CST 2009

What you suggest poses a unique problem however because the java would have to know ahead of time (prior to calling xquery) if the string being passed will be used in an evaluation. This limitation with external variables of having to pre-evaluate passed elements is a large hole for us. The middle tier that is passing the query arguments doesn't know what variables will be used for evaluation however the XQuery string/document has this information. To ensure that string variables that need to be evaluated can be evaluated we opted to create a token preprocessor vs. building logic into the java to predetermine if it should evaluate the variable to an element.

As an example parsing the following has this issue:

Exist xquery -
xquery version "1.0";

import module namespace util="http://exist-db.org/xquery/util";
declare variable $path as xs:string external;

        $query := concat('for $x in collection()',$path, ' return $x')
        return util:eval($query)

Desired xquery -
xquery version "1.0";

declare variable $path as xs:string external;

for $x in collection()$path return $x

Token syntax for achieving desired xquery-
xquery version "1.0";

for $x in collection()${path} return $x

Result of preprocessing on tokens-
xquery version "1.0";

for $x in collection()/mypath[@id='myid'] return $x

Our preprocessor handles a little more than is shown but the example above is the general idea behind our preprocessor.

-- Paul Ryan

-----Original Message-----
From: Florent Georges [mailto:]
Sent: Monday, January 12, 2009 10:55 AM
To: Paul Ryan; 
Subject: Re: [oXygen-user] Preprocessing Xquery

Paul Ryan wrote:

> Sure the limitation has to do with working with Java and XQuery
> together. When paired, to pass data down to the XQuery, it ends up
> being passed as strings which with an engine like eXist the data
> needs to be evaluated with a special utility extension.

  I am sorry to use oXygen band-width for what seems to be a general
XQuery question, but I am really intrigued: do you mean the usual way
of passing variable to a query (using external variables) does not work
with eXist, from Java?

  Because if it is just a matter of passing strings to the query, I
would personally rather use external variables in the query, set them
from the calling Java code, and not use any pre-processing phase; in
other words always use only standard queries.

  But I guess I missed something.


Florent Georges

More information about the oXygen-user mailing list