Reputation: 4291
I have a query that specifies in a file the document to read.
I need to execute this query against many files, so I'd need something like passing the filename from the commandline.
I don't know how to do this. How can I solve my problem?
An example of my query file is
for $i in doc("myfile")
return $i
and I'm running it with this commandline
#!/bin/bash
java -cp "./tagsoup/tagsoup-1.2.1.jar:./saxon/saxon9he.jar" net.sf.saxon.Query -x:org.ccil.cowan.tagsoup.Parser $1
Upvotes: 2
Views: 517
Reputation: 163262
The simplest approach is to pass the source document as the context item for the query. Change the query to
for $i in . return $i
(which simplifies to just ".")
and set the source document in the -s:source.xml
option on the command line.
You can also declare external variables in the query and set them from the command line, for example
declare variable $uri external; doc($uri)
then
java net.sf.saxon.Query -q:query.xq uri=source.xml
I guess from the question that you didn't manage to find the documentation for the Saxon XQuery command line: it is here:
http://saxonica.com/documentation/index.html#!using-xquery/commandline
Note that although this is the direct answer to your question, you will get much better performance using the collection() approach suggested by @DanielHaley, because it avoids the overheads of initialising the Java VM and compiling the query for each file that is processed.
Upvotes: 2