Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT 2.0 transformation via linux shell

I want to perform an XSLT 2.0 transformation by the use of command line executions. I heard that i could use the Saxon library by a shell command like java -jar sax.jar -input foo.xml -xsl foo.xsl -output bar.xml. Does anyone know how exactly i can achieve that goal?

By the way, i am not limited to Java. Any other shell solution is fine.

like image 490
Alp Avatar asked Dec 16 '11 15:12

Alp


2 Answers

The documentation of Saxon is online: http://www.saxonica.com/documentation/#!using-xsl/commandline. So you need java -jar saxon9he.jar -xsl:foo.xsl -s:foo.xml -o:bar.xml.

like image 57
Martin Honnen Avatar answered Oct 27 '22 00:10

Martin Honnen


Update: check solution 2 and 3 if your java is version 11 or later, where .internal. are not available anymore.

I just wrote this bash script to use com.sun.org.apache.xalan.internal.xsltc.cmdline classes for transforming XML. Works with openjdk just fine. Not a solution for production use cases but handy for debugging.

P.S. took the idea from this blog

  • SOLUTION 2: use xalan command line
  • SOLUTION 3: https://github.com/physikerwelt/xstlprocJ
like image 41
akostadinov Avatar answered Oct 27 '22 02:10

akostadinov