#!/usr/local/bin/python

"""
This script will invoke the XSLT processor and automatically will generate
the class path for you.

You need to edit the following variables:
JAVA_LOCATION:
  Windows: something like r"c:\jdk1.x.y\bin"
  Unix: something like "/usr/local/jdk1.x.y/bin"

JAR_DIRS
  The full or relative path to you Xalan directory. If you put multiple 
  directories in this list, make sure there are NO duplicate jar files or
  you'll receive error messages.
"""

import sys
import os
import os.path
import classpath
import string

JAVA_LOCATION = '/usr/local/jdk1.2.2/bin'

JAR_DIRS = [ 'xalan-j_2_4_1/bin']

JAR_FILES = [ 'BCEL.jar', 'java_cup.jar', 'xalan.jar', 'xercesImpl.jar',
'JLex.jar', 'regexp.jar', 'xml-apis.jar', 'bsf.jar',
'runtime.jar', 'xalanservlet.jar', 'xsltc.jar'
]


cp = classpath.compute_classpath(JAR_DIRS, JAR_FILES)

args = sys.argv[1:]
if len(args) != 3:
   print "usage: do_xslt input-file.xml xslt-file.xsl output-file.xml"
   sys.exit(1)

java_path = os.path.join(JAVA_LOCATION, 'java')

parms = {
	'java' : java_path,
	'in' : args[0],
	'xsl' : args[1],
	'out' : args[2],
	'classpath' : cp
}

go_xslt = "%(java)s -classpath %(classpath)s org.apache.xalan.xslt.Process\
	 -IN %(in)s -XSL %(xsl)s -OUT %(out)s"

go_xslt = go_xslt % parms
print go_xslt
os.system(go_xslt)
