What  I am trying to do is issue Xquery against a XML database (ex: BaseX), from a step inside the XProc pipeline.  I am using calabash XProc engine which uses Saxon API to process Xquery and XQJ support to connect and query a  datasource. I have specified snippet of XQuery code in calabash which uses saxon  api to process Xqueries.  As you can see from the below code  there is no reference to SaxonXQDatasource. ?


What  I am trying to understand is whether saxon api can automatically figure out based on the parameters(ex: db URI, user name , password) in the  saxon config file  to connect and issue queries against the  target data source (in my case it is Basex database).


Is my understanding wrong?  Do we need to explicitly instantiate the XQDataSource in the code?  Also, can somebody provide an example how to connect to a database using SAXON API? I am looking for where to specify the db uri, user name and password in SAXON. I donít see any example of how to connect to database in xqj samples provided in SAXON resources package.


    Vector<XdmNode> defaultCollection = new Vector<XdmNode> ();

        while (source.moreDocuments()) {




        XdmNode document = null;

        if (defaultCollection.size() > 0) {

            document = defaultCollection.firstElement();



        XdmNode root = S9apiUtils.getDocumentElement(query.read());

        String queryString = null;


        if ((XProcConstants.c_data.equals(root.getNodeName())

             && "application/octet-stream".equals(root.getAttributeValue(_content_type)))

            || "base64".equals(root.getAttributeValue(_encoding))) {

            byte[] decoded = Base64.decode(root.getStringValue());

            queryString = new String(decoded);

        } else {

            queryString = root.getStringValue();



        Configuration config = runtime.getProcessor().getUnderlyingConfiguration();


        CollectionURIResolver collectionResolver = config.getCollectionURIResolver();


        config.setCollectionURIResolver(new CollectionResolver(runtime, defaultCollection, collectionResolver));


        Processor qtproc = runtime.getProcessor();

        XQueryCompiler xqcomp = qtproc.newXQueryCompiler();


        XQueryExecutable xqexec = xqcomp.compile(queryString);

        XQueryEvaluator xqeval = xqexec.load();

        if (document != null) {




        for (QName name : params.keySet()) {

            RuntimeValue v = params.get(name);

            if (runtime.getAllowGeneralExpressions()) {

                xqeval.setExternalVariable(name, v.getValue());

            } else {

                xqeval.setExternalVariable(name, new XdmAtomicValue(v.getString()));





        Iterator<XdmItem> iter = xqeval.iterator();

        while (iter.hasNext()) {

            XdmItem item = iter.next();

            if (item.isAtomicValue()) {

                throw new XProcException(step.getNode(), "Not expecting atomic values back from XQuery!");


            XdmNode node = (XdmNode) item;


            if (node.getNodeKind() != XdmNodeKind.DOCUMENT) {

                // Make a document for this node...is this the right thing to do?

                TreeWriter treeWriter = new TreeWriter(runtime);




                node = treeWriter.getResult();