I need a simple command line program to transform XML using an XSL Stylesheet

22,699

Solution 1

Have you tried 'xsltproc'? It's probably already installed.

http://xmlsoft.org/XSLT/xsltproc2.html

Solution 2

I'd recommend Saxon, which can be run from the command line like so:

java -jar /path/to/saxon.jar xmlfile xslfile

Solution 3

Have you seen XMLStarlet (an XML command line toolset) ? It does lots of XML-related querying transformation, and in particular:

xml tr --help
XMLStarlet Toolkit: Transform XML document(s) using XSLT
Usage: xml tr [<options>] <xsl-file> {-p|-s <name>=<value>} [ <xml-file-or-uri> ... ]
where
   <xsl-file>      - main XSLT stylesheet for transformation
   <xml-file>      - input XML document file name (stdin is used if missing)
   <name>=<value>  - name and value of the parameter passed to XSLT processor
   -p              - parameter is XPATH expression ("'string'" to quote string)
   -s              - parameter is a string literal

Further documentation here.

Solution 4

If I assume correctly that you want to supply a stylesheet and an XML document then Xalan-J has a command line feature you can use to do this:

http://xml.apache.org/xalan-j/commandline.html

which can be invoked with:

java org.apache.xalan.xslt.Process -IN foo.xml -XSL foo.xsl -OUT foo.out

Solution 5

http://xml.apache.org/xalan-j/

Share:
22,699
Admin
Author by

Admin

Updated on October 26, 2020

Comments

  • Admin
    Admin over 3 years

    I am on OSX Snow Leopard (10.6.2) I can install anything I need to. I would preferably like a Python or Java solution. I have searched on Google and found lots of information on writing my own program to do this, but this is a just a quick and dirty experiment so I don't want to invest a lot of time on writing a bunch of code to do this, I am sure someone else has done this already.

    This is off-topic now, do not use this question as an example of why your recommendations request is on topic, it is not. I apologize, but my Google-Foo was failing me the day I asked this 4 years ago!