Saxon and XQuery : how not to repeat the XML source file name in the query ?

P

pepin_labulle

I'm a newbie with XQuery and I'm trying to execute a query with Saxon.
If I don't specify the XML source file name in the query, Saxon raises
the following error :
javax.xml.transform.Transforme­rException: Finding root of tree: the
context item is not set
Even if I specified the source file name in the command line.

Here is the command line I used :
java -cp saxon8.jar net.sf.saxon.Query -s books.xml books.xq

where books.xq =

xquery version "1.0";
for $b in //BOOKS/ITEM
order by string-length($b/TITLE) return
<book>
<author> { $b/AUTHOR } </author>
<title> { $b/TITLE } </title>
</book>

I can avoid the error by using this line in the query :
for $b in doc("books.xml")//BOOKS/ITEM

But, I don't want to repeat the file name in the query. I'd like to use
the same query whatever the file name is.
Is it possible ?

Actually, Saxon behaves the same in command line or called from a java
program.
I used a utility called bumblebee to test my query with different
XQuery processors, and i get the same result with Qizx.

Thank you and excuse my english.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top