2
votes

I'm very new to this.

I have a query and an xml file.

I can write a query over that specific file

for $x in doc("file:///C:/Users/Foo/IdeaProjects/XQuery/src/books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title

I have a basic xml file, with books in it, works nicely in intellij.

but if I wanted to run this query against some file defined on the command line, then how do I do it?

the command line for running the above is (as much for other peoples reference)

java -cp C:\Users\Foo\.IdeaIC2019.2\config\plugins\xquery-intellij-plugin\lib\Saxon-HE-9.9.1-7.jar net.sf.saxon.Query -t -q:"C:\Users\Foo\IdeaProjects\XQuery\src\w3schools.com.xqy"

and that also works nicely.

the saxon documentation

https://www.saxonica.com/html/documentation/using-xquery/commandline.html

implies that I can specify an input file, using "-d" and "The document node of the document is made available to the query as the context item"

but this doesnt really make any sense to my 1 day old XQuery skills.

how do I specify the document is sent from the command line in the query? what is the context item? and how do I reference it?

(I can do a bit of XSLT 1.0, so I understand the notion of a context).

2

2 Answers

1
votes

I think the option is named -s (for source) so you can use -s:books.xml and inside your XQuery main expression any path is evaluated with that document as the context item so you can just use e.g.

for $x in /bookstore/book
where $x/price>30
order by $x/title
return $x/title
1
votes

and the answer is to drop the doc() function

for $x in bookstore/book

i.e. the same notion as xslt.