XSLT 2.0 transformation via linux shell
Solution 1
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
.
Solution 2
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
![Alp](https://i.stack.imgur.com/C45lx.jpg?s=256&g=1)
Alp
I am passionate for all topics related to web development. In particular i enjoy writing code in Python and JavaScript. I love opportunities to learn about state-of-the-art techniques, developing useful features with pleasant UX and establishing stable build and deploy chains.
Updated on July 20, 2022Comments
-
Alp almost 2 years
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.
-
Vincent Biragnet over 12 yearsBe aware that a Sax parser does not perform XSLT. Sax parser parse XML in a stream and fire events. Saxon is an XSLT processor. Most of the time a XSLT processor does not stream. Saxon (in his commercial version) has streaming capabilities with the latest instructions provided by XSLT 3.0.
-
Alp over 12 yearsthanks for clarification of correct naming
-
-
Alp over 12 yearsthanks alot. i also found this: manpages.ubuntu.com/manpages/oneiric/man1/saxonb-xslt.1.html is that good too or what would you prefer?
-
Michael Kay over 12 yearsThe version of Saxon shipped with your Ubuntu distribution is probably rather old. It's probably better to download the most recent version (though if you're a beginner you probably won't notice much difference).
-
febot about 3 yearsIt seems, like all
.internal.
stuff, it goes away after some time... So your bash script ends up with ClassNotFoundException with JDK 11 -
akostadinov about 3 years@OndraŽižka, you are right. I've updated answer with another solution. Do you think Java stopped to embed XSLT or rather we have no way to access it anymore?