Difficulty getting Saxon into XQuery mode instead of XSLT

一个人想着一个人 提交于 2019-12-04 09:24:22

I don't have problems with this command-line usage:

java -cp C:\xml\Parsers\Saxon\HE-9-2-0-6\saxon9he.jar net.sf.saxon.Query
-q:"C:\Program Files\Oxygen XML Editor 11\samples\xquery\Books\authors.xquery"

Michael Kay

When you use "java -jar saxon9he.jar", you are asking Java to invoke the default entry point in the JAR file, which is net.sf.saxon.Transform. To enter at a specific entry point, for example net.sf.saxon.Query, you need to use the form "java -cp saxon9he.jar net.sf.saxon.Query".

  1. pre-preparations
  2. Download the Saxon: first you should download the Saxon package at http://sourceforge.net/projects/saxon/ and unzip it at some directory like D:\Program Files\SaxonHE9-5-0-1J.
  3. Get Source code: If your want the source code, download it at http://nchc.dl.sourceforge.net/project/saxon/Saxon-HE/9.3/saxon-resources9-3.zip before you unzip it into the SaxonHE9-5-0-1J dir;
  4. Build Workstation: prepare the workstation for you to exercise: it's at SaxonHE9-5-0-1J\iexercise where you can put your *.xq files and its results; you can also make a directory named icache to hold your caches;
  5. Let Java know where to find the interpreter: To make it work well for Xquery statements, your should add the core package to interpret it to the windows environment: open the command line and change to SaxonHE9-5-0-1J and run after you copy the saxon9he.jar into jdk1.7.0\lib:

    set classpath=.;%java_home%\lib\saxon9he.jar

  6. Test if it's known: So normally you can run the xquery scripts now after Step 4 run right. If you're not sure of it still, chech it with: java net.sf.saxon.Query 2.Prepare your first launch

  7. Make a file(for example, named test.xq) with affix .xq, .xquery or .xqy in iexercise, its content is displayed below:

    doc(“catalog.xml”)/catalog/product[@dept = “ACC”]

  8. Copy the pre-done file catalog.xml into . /.

  9. Run java net.sf.saxon.Query -q:test.xq -o:result.xml the first arguement indicates the interpreter to compile xquery file, which is your labor in Step 1.4, -q:filename is the file that will be compiled with the xquery statements, and the third shows where to put the result; if not specified, is will be dispalyed at the standard output.

The catalog file:

<catalog>
    <product dept="WMN">
        <number>557</number>
        <name language="en">Fleece Pullover</name>
        <colorChoices>navy black</colorChoices>
    </product>
    <product dept="ACC">
        <number>563</number>
        <name language="en">Floppy Sun Hat</name>
    </product>
    <product dept="ACC">
        <number>433</number>
        <name language="en">Deluxe Travel Bag</name>
    </product>
    <product dept="MEN">
        <number>784</number>
        <name language="en">Cotton Dress Shirt</name>
        <colorChoices>white green</colorChoices>
    <desc>Our <i>favorite</i> shirt!</desc>
    </product>
</catalog>

Note that the documentation on saxonica does not say

java -jar saxon9he.jar net.sf.saxon.Query -q:myQuery.xql

(it isn't an executable jar file and you don't need -q at all if the xql file is the last option) so the following will work

java net.sf.saxon.Query myQuery.xql 

or

java -cp C:\downloads\saxon\saxon9he.jar net.sf.saxon.Query myQuery.xql
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!