You can declare an external variable in your query like this:
 
declare variable $labelLinkUri as xs:string external;
 
You can then reference the variable like this:
 
let $x := doc($labelLinkUri) return ...
 
And then you can bind a value to the variable in your XQJ application code as:
 
expr.bindString(new QName("labelLinkUri"), "file:///c:/Users/A/Documents/Sweta..../xyz.xml", null)
 
Note that XQuery expects to deal with URIs, not file names.
 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Sweta Kedia [mailto:swetakedia@gmail.com]
Sent: 11 February 2010 05:13
To: saxon-help@lists.sourceforge.net
Subject: [saxon] How can I dynamically pass filename to xquery Files.

Hi,

I have a separate xquery file which I am calling through java as follows:

rule2= new FileInputStream("C:/Users/A/workspace/Validator/xqFiles/Rule2.xq");
 SaxonXQPreparedExpression expr = (SaxonXQPreparedExpression) con.prepareExpression(rule2);

 In Rule2.xq I have some filepaths as:


let $labelLinkFile:="C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2008/Quarterly/2nd Quarterly/bvf-20081231/bvf-20081231_lab.xml"
let $x:= fn:doc("C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2008/Quarterly/2nd Quarterly/bvf-20081231/bvf-20081231.xml")//*[@contextRef and @unitRef]
let $pre:= fn:doc("C:/Users/A/Documents/Sweta/users/sweta231119791251796126671/Other/2008/Quarterly/2nd Quarterly/bvf-20081231/bvf-20081231_pre.xml")/linkbase/presentationLink

I want that these filepath should be dynamically passed through java.
Please tell me how can this be done.

With Regards

Sweta.