Making XQuery calls from XSL

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Making XQuery calls from XSL

cmarchand

 

 

Hello,

 

I need, from a XSL transformation, to retrieve data from a XML Database via XQuery. Before writing an extension function, is there such an existing function ?

 

If not, in case of xquery result is a sequence, I will need to build a sequence of document-fragments while reading server results. DocumentBuilder does not provide a method that returns many XdmNode ; does that mean I will have to build many XdmNode, reading the sequence elements from response, and then build a Sequence to wrap all XdmNode previously built ?

 

Thanks in advance,

Christophe


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Making XQuery calls from XSL

Michael Kay
XQuery 3.1 provides a function load-xquery-module(), which Saxon will implement in version 9.7.

However, this might not be much use to you, because by the looks of it you don't want a Saxon XQuery engine, you want an XQuery engine that can query your chosen XML database. So I guess the answer might depend on what database you are using.

If you're getting the data from an external source, then obviously the way you turn it into a sequence of Saxon nodes will depend on what form the data takes. It also depends on whether you want to return the data incrementally, or whether you're prepared to have it all sitting in memory in a single lump.

If, for example, you are accessing the external database using an XQJ interface, then you can get the results back as (effectively) an iterator over DOM nodes (XQJ has a most peculiar way of doing iterators, but we can ignore that). If the results already exist in DOM form, then it's probably best to pass them to Saxon as wrapped DOM nodes, even though Saxon access to DOM is not the most efficient. To do this you would typically implement a SequenceIterator:

SequenceIterator results = new SequenceIterator() {

   public Item next() {
      Node node = ... get next node from database query result ...
      return new DocumentWrapper(node, "", context.getConfiguration();
   }

   ....

}

return new LazySequence(results);


On 18 Nov 2015, at 10:31, [hidden email] wrote:

 
 

Hello,

 

I need, from a XSL transformation, to retrieve data from a XML Database via XQuery. Before writing an extension function, is there such an existing function ?

 

If not, in case of xquery result is a sequence, I will need to build a sequence of document-fragments while reading server results. DocumentBuilder does not provide a method that returns many XdmNode ; does that mean I will have to build many XdmNode, reading the sequence elements from response, and then build a Sequence to wrap all XdmNode previously built ?

 

Thanks in advance,

Christophe

------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help