Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

<xsl:template match="/">
  <xsl:copy-of select="saxon:evaluate($xpath-param)"/>
</xsl:template>

Also other possibility is to use their Java API: http://www.saxonica.com/documentation/xpath-api/intro.xml but I don't know Java

Is there any way to make Saxon evaluate XPath expression from command line?
Shell script would be sufficient, too, if possible

Update:
Browsing Saxon documentation, I found out about XPathExample sample. Unfortunately I can't make use of it

like image 917
theta Avatar asked Oct 26 '25 23:10

theta


1 Answers

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

<a>
  <b id="x"/>
  <b id="z"/>
  <b id="x"/>
</a>

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

<b id="x"/><b id="x"/>

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

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

like image 104
Daniel Haley Avatar answered Oct 28 '25 22:10

Daniel Haley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!