How to use Saxon XPath processor w/o coding in Java

后端 未结 3 1198
时光说笑
时光说笑 2021-01-14 08:52

I guess I could make some XSL stylesheet, then use it as a template with parameter option to evaluate XPath expression with Saxon XSLT processor on command line, like:

3条回答
  •  深忆病人
    2021-01-14 09:35

    You can run Saxon (XQuery) from the command line. You can do this by pointing to a file that has the XPath/XQuery using -q or you can pass the query string directly using -qs.

    Here's an example of using -qs to process a simple XPath:

    input.xml

    
      
      
      
    
    

    Saxon command line (I used Saxon9-HE to test with)

    java -cp "saxon9he.jar" net.sf.saxon.Query -s:"input.xml" -qs:"/a/b[@id='x']" -o:"results.xml"
    

    results.xml

    
    

    Note: I could've made my output well-formed by changing the -qs to something like this: -qs:"{/a/b[@id='x']}".

    For more command line options, look here: http://www.saxonica.com/html/documentation/using-xquery/commandline.html

提交回复
热议问题