xquery collection() on eXist collection

Oxygen general issues.
jacquesfauquex
Posts: 3
Joined: Thu May 29, 2008 10:44 pm

xquery collection() on eXist collection

Post by jacquesfauquex »

I have no problem with applying a XQuery to a folder in the file system
for $book in collection("/collection")//book


I have no problem with applying a XQuery to the URI of a resource in eXist database.
for $book in doc("http://127.0.0.1:8080/exist/rest/db/myC ... atalog.xml") //book


But I can't find the right syntax to query a collection in the eXist database, that is, by reference to the URI of the collection. I would naturally try...

for $book in collection("http://127.0.0.1:8080/exist/rest/db/myCollection") //book

... but it doesn't work. I read that : "collection(), returns a sequence of nodes corresponding to a given URI. Exactly how each URI resolves to a set of nodes depends on the server and its configuration."

So, what is the right syntax or configuration in oxygenxml to XQuery an eXist collection ?


Thanks a lot,

Jacques Fauquex
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: xquery collection() on eXist collection

Post by alex_jitianu »

Hello,

When executing an eXist XQuery in oXygen, the collection URI must be given relative, like this :

for $book in collection("/db/myCollection")//book

Also before running an XQuery against eXist you must create an eXist connection and use that connection as the XQuery processor.

A detailed demonstration about how to configure eXist support and how to execute an XQuery using eXist can be found here : http://www.oxygenxml.com/demo/eXist/eXist.html

Best regards,
Alex
jacquesfauquex
Posts: 3
Joined: Thu May 29, 2008 10:44 pm

Re: xquery collection() on eXist collection

Post by jacquesfauquex »

Hi Alex

Thanks for the link to the neat demo on how to set up exist in Oxygen and XQuerying it.

Apart from the use of a relative path, my second mistake was I forgot to configure the Execute XQuery Scenario as described in the demo.

Now it works fine.

Best greetings.

Jacques
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

So, I have a similar problem except I'm trying to execute the collection function within an XSLT stylesheet, e.g.

<xsl:for-each select="collection( 'oxygen:/myExistDB/db/sales' )">
<xsl:message>Found <xsl:value-of select="." /></xsl:message>
</xsl:for-each>

And I get this error:

F [Saxon-B 9.1.0.5]: java.io.IOException: Resource not found :db/sales - Resource not found :db/sales - 239:0

I had a look at the link above, but that didn't help - I already have access to my eXist set up and can see and use all the resources no problem.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: xquery collection() on eXist collection

Post by sorin_ristache »

Hello,

Usually an eXist collection is processed with an XQuery executed by the eXist DB engine. You can access the same collection in XSLT using an external engine (for example Saxon 9 in your case) with the general URL support for accessing a resource through a URL: Oxygen provides the content of the collection() parameter to Saxon 9 as the content of a URL with the scheme oxygen. The problem is that the default Saxon collection URI resolver used in the evaluation of collection() calls handles files and directories in different ways only if the parameter of collection() is a file URL (file://...). For all the other types of URLs Saxon 9 handles the parameter as a reference to a collection catalog, that is an XML file which lists all the collection files, for example:

Code: Select all

<collection stable="true">
<doc href="dir/chap1.xml"/>
<doc href="dir/chap2.xml"/>
<doc href="dir/chap3.xml"/>
<doc href="dir/chap4.xml"/>
</collection>
That means your collection() calls will succeed with the default collection resolver of Saxon 9 only if the parameter points to the URL of a collection catalog file, for example:

Code: Select all

<xsl:for-each select="collection('oxygen:/eXist-source$eXist-connection/db/personal/catalog.xml')">
<xsl:message> ...
If you want to override this default behavior you can set your own collection catalog resolver for Saxon 9 in Oxygen.


Regards,
Sorin
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

Okay, this is driving me nuts! I just cannot get Saxon to search my eXist database with the collection() function in XSL at all. :(

I do not want to do it automatically or all the time; it has to be done on a transformation by transformation basis, i.e. some transformations need to search eXist, some need to search the normal directories.

I cannot find any advice on building a collection catalogue so I can't work out if the entries in the catalogue can be directories or if they have to be files. If they have to be files, this cannot be used as a solution because the catalogue needs to allow for every document in the database, new ones of which are being added all the time.

And I don't think I can use my own collection URI resolver, because I presume I have to write one in Java - which I can't do, and even if I don't have to write my own:
  • what do I use and where can I get it; and
  • how do I set it up so it only comes into effect when it's the eXist database I want to search?
So I gave up using XSL and tried XQuery instead, but if I use the transformation
Execute XQuery on eXist
I always get this error no matter what I do:
Engine name: Saxon-B XQuery 9.1.0.7
Severity: error
Description: Resource not found :db/nehta/ndsm/dev/data/*
(incidentally, nowhere in my XQuery am I specifying
db/nehta/ndsm/dev/data
so why it's searching there is beyond me!). And if I use the
Execute XQuery v10.3
I get the same errors as I do with XSL.

Even the most trivial XQuery fails, e.g.

Code: Select all

for $x in collection( '/db' ) return $x
or

Code: Select all

for $x in collection( 'oxygen:/myeXist/db' ) return $x
.

Any and all advice gratefully accepted.
Stephen
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

BTW, using WebDAV - i.e. http://my-exist-server:8080/exist/webdav/db - doesn't work either. :(
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

A further clarification:

After some additional research, it appears that the "Execute XQuery on eXist" is my own transformation and that's where the "/db/nehta/ndsm/dev/data" is coming from. I had put this URL - "oxygen:/eXist$my-exist/db/nehta/ndsm/dev/data/*" - in the XML URL field.
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

Which also explains why the trivial XQuery fails. :oops:

Anyway, using the collection() function still does not work (because it insists that it must be a catalogue!). :(

And I tried creating a catalogue with a single <doc> element that points to a directory in the eXist database, and - no surprise - it doesn't work either. :|
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

Finally I figured this out. :D :D

I basically need to use eXist as the XQuery engine and not Saxon and - for anyone else whoever gets frustrated by this - you do this by selecting your eXist database connection in the "Transformer" field/option of your transformation scenario.

To those who look after the documentation, I'm no expert, but I'm no bunny either and I don't know whether I just missed it, but to me this was not at all clear from the documentation. :?

Stephen
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: xquery collection() on eXist collection

Post by adrian »

Hi,

Don't want to rub this in, but you do realize that the second post on this thread mentioned what you just discovered. ;)
alex_jitianu wrote:When executing an eXist XQuery in oXygen, the collection URI must be given relative, like this :

for $book in collection("/db/myCollection")//book

Also before running an XQuery against eXist you must create an eXist connection and use that connection as the XQuery processor.

A detailed demonstration about how to configure eXist support and how to execute an XQuery using eXist can be found here : http://www.oxygenxml.com/demo/eXist/eXist.html
Regards,
Adrian

PS: I've added an issue on our issue tracking tool to add a screenshot of the configuration of the eXist XQuery transformation instead of just writing about it in the user guide and on the site.
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Rumplestiltzkin
Posts: 28
Joined: Thu Mar 12, 2009 4:16 am

Re: xquery collection() on eXist collection

Post by Rumplestiltzkin »

I did see it, but I thought it was just about creating an eXist connection which I've had for years. :oops:
Post Reply