views:

307

answers:

7

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.

+2  A: 

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

S.Lott
+4  A: 

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

nosklo
+3  A: 

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
Jon
+1  A: 

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
+2  A: 

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

java -jar /path/to/saxon.jar xmlfile xslfile
Will McCutchen
+4  A: 

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

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

nbeyer
you are right OSX Snow Leopard 10.6.2 already has this installed, so it gets the check mark!
fuzzy lollipop
A: 

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