[MarkLogic Dev General] Referencing a string variable
dsokolsky at marklogic.com
Tue Jun 26 11:59:44 PDT 2007
I think the key is that you need to define your external variable as
type cts:query. Passing in the external variable is definitely the
preferred technique over using xdmp:eval. Here is a simple example:
Suppose you have a file on your app server root named invoke.xqy with
the following contents:
define variable $query as cts:query external
You can then invoke this XQuery module, passing it a cts:query, by
issuing a query as follows:
xdmp:invoke("invoke.xqy", (xs:QName("query"), cts:word-query("foo")))
You can have some logic in this module to construct the cts:query to
make it dynamic (based on user inputs, for example). For a brief
example of how you might do that, see the "Creating a cts:query Parser"
section in the "Composing cts:query Expressions" chapter of the
Does that help?
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of Mattio
Sent: Tuesday, June 26, 2007 10:48 AM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] Referencing a string variable
I'm curious about something and I was wondering if anyone has some
I have a query saved on the file system so I can call it via XCC from my
web application. The parts of interest are:
let $PARSED_QUERY := cts:and-query( ( cts:word-query("christmas",
"diacritic-insensitive")) ) )
let $SEARCH := cts:search( //(entry | section), $PARSED_QUERY) let
$ESTIMATE := cts:remainder($SEARCH) ...go on to do other
This works perfectly fine as is.
I plan on changing $PARSED_QUERY so it's a variable with an external
source. I attempted this by changing the definition to define variable
$PARSED_QUERY as xs:string external, but I started getting errors.
After a little debugging, I went back to my test query above and changed
the let definition to be:
let $PARSED_QUERY := 'cts:and-query( ( cts:word-query("christmas",
"diacritic-insensitive")) ) )'
Turns out that treating $PARSED_QUERY as a string throws an error. That
makes sense after looking at the definition for cts:search.
By chance, I tried wrapping $PARSED_QUERY in xdmp:eval() and then I
could pass the value in as a string and have the search execute
properly. All is well again in my little corner of the world.
But, is there a more proper or efficient way to pass in this variable so
it can be referenced inside of cts:search? Or is there a way to convert
it properly using XQuery?
General mailing list
General at developer.marklogic.com
More information about the General