16

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!

8 Answers8

24

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

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

nbeyer
  • 1,157
  • 10
  • 14
17

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

java -jar /path/to/saxon.jar xmlfile xslfile
Will McCutchen
  • 13,047
  • 3
  • 44
  • 43
5

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.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
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
Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
3

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

S.Lott
  • 384,516
  • 81
  • 508
  • 779
3

Use lxml. It is very easy to use and very fast. It can work with XPath and includes a XSLT transformer.

nosklo
  • 217,122
  • 57
  • 293
  • 297
0

see this question for another solution with com.sun.org.apache.xalan.internal.xsltc.cmdline.Transform. But I noticed some weirdness with namespaces compared to xalan processing. Be aware behavior might be non standard.

Also you know, internal java classes are not good to rely on.

Community
  • 1
  • 1
akostadinov
  • 17,364
  • 6
  • 77
  • 85
0

I have used Saxon 6.5 for years for command line transformations. (Java, XSLT 1)

An excellent fallback if a native solution is not available.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347