How do I set unix command line parms to call Saxon-he

Cathy Wilbur

Well Known Member
Want to write a command line to call Saxon processor from a unix script line. Am using Saxon-HE from Unix command line to convert my XML file into a CSV file so it can be uploaded into a DB Table. We are using the DB table as input into our AP interface in ERP E1. Had to switch to Saxon processor because xsltproc does not work with xsl 2.0.

In the command line call I need to specify two classpaths (Classpath for JAVA, Classpath for SAXON jar files)

How would I call the saxon processor in a unix script and pass it the following information
JavaClassPath, SaxonJarClassPath, InputFile, StylesheetFile, OutputFile

So far this is the unix command line I came across on the web. Where would I find all the Saxon command line options to call from a unix shell script.
We have Java on Unix box. Loaded Saxon jar files in a different directory on unix box. Loaded stylesheet on unix box. Loaded InputFile on unix box.

Is this the correct command line to use in my Unix shell Script? Can I specifiy jar file for saxon plus class path. Also, is this how saxon is called from the command line

saxon –jar:saxonjarclasspath/saxon9he.jar -m:javaclasspath??? -s:Input_File -xsl:Stylesheet_File –o:Output_File

java -jar:</path/to/saxon.jar> -s:</path/to/input.xml> -xsl:</path/to/stylesheet> -o:</path/to/outputfile.csv>
Last edited:
Got the call to Saxon-he working in Unix so here is the code. (took time to resolve class path and properly set up Saxon java call syntax thru Unix shell script)

Unix ClassPath Code
You must set your class path so your Java directory, and Jar directory are part of the class path.
Your path commands may be slightly different but you get the idea.

export JAVA_HOME

export PATH=$PATH:$SYSTEM/bin32:$JAVA_HOME/bin
export ICU_DATA=$SYSTEM/locale/xml/

Unix Code to do conversion
You will notice that one java call has $CLASS_PATH and the other has $SAXON_JAR but both calls work fine. (one I commented out)
Reason I put $SAXON_JAR so that the programmer can easily determine from java call what jar file I am executing.
You must specify -cp to indicate that you want Java to use whatever directories are specified in your class path.
Directories where java is and jar file is located need to be included in your class path

# 5) Convert Library A/P Interface file from XML to CSV
# If the file exists then convert XML file to a CSV file
# ==================================================================
if [ -s $FinesrvDataDir/Library_Invoice_Interface.xml ]
# Initialize Java Environment
# Change the directory to execute the Java SAXON-HE XSL Processor to convert XML file to CSV
# ==================================================================
cd $FinesrvJavaDir
#. /usr/java5/bin/xxxx???

# Saxon-HE (home edition) is an open source version of processor written in Java.
# Saxon XSL processor will execute the stylesheet
# The stylesheet specifies the specific rules as to how the XML file is to be converted.
# This command below is used to call the Saxon processor
# java -jar:/classpath/saxon9he.jar -s:/classpath/InputFile.xml -xsl:/classpath/stylesheet.xsl -o:/classpath/OutputFile.csv
# ==================================================================
echo $SAXON_JAR net.sf.saxon.Transform \ -s:$FinesrvDataDir/Library_Invoice_Interface.xml -xsl:$FinesrvCronDir/LibrXML2CSV_stylesheet.xsl -o:$FinesrvDataDir/Library_Invoice_Interface.csv
#java -cp $CLASS_PATH net.sf.saxon.Transform -s:$FinesrvDataDir/Library_Invoice_Interface.xml -xsl:$FinesrvCronDir/LibrXML2CSV_stylesheet.xsl -o:$FinesrvDataDir/Library_Invoice_Interface.csv
java -cp $SAXON_JAR net.sf.saxon.Transform -s:$FinesrvDataDir/Library_Invoice_Interface.xml -xsl:$FinesrvCronDir/LibrXML2CSV_stylesheet.xsl -o:$FinesrvDataDir/Library_Invoice_Interface.csv
# 6) Remove XML Library A/P Interface file
# Remove XML file once it is converted
# =====================================
#rm $FinesrvDataDir/Library_Invoice_Interface.xml