source: CommonItems/trunk/XSLT/one-off_XSLT/ @ 1136

Subversion URL:
Revision 1136, 1.1 KB checked in by selatham, 14 years ago (diff)

added script for running any xslt over dir of xml files

1#!/usr/bin/env python
2"""This is for running a one-off xslt over xml files within given directory structure tree.
3    The output files have same name as input with _new appended.
4    Usage:
5    python run_oneoff_xslt arg1 = name of xslt file
6                           arg2 onwards = list of filenames. If not specified use all xml files in current dir.
8import string, os, sys
9numfilesproc = 0
10if len(sys.argv) <2:                    #if no filenames are specified use current dir
11        sys.exit("must supply name of xslt file as first argument")
13xslt_name = sys.argv[1]
15if len(sys.argv) ==2:                   #if no filenames are specified use current dir
16        filenames = os.listdir(os.curdir)
18        filenames = sys.argv[2:]
20for filename in filenames:
21        if filename.find('.xml') != -1:
22                outfile=string.split(filename,'.xml')[0] + '_new.xml'
23                commandline = "java org.apache.xalan.xslt.Process -IN %s -XSL %s -OUT %s" %(filename, xslt_name, outfile)
24                print commandline
25                os.system(commandline)
26                numfilesproc += 1
27        else:
28                print 'File %s is not xml format. Not processed'  %filename
30print " Procedure %s ran to end" %xslt_name
31print "No. of files processed = %s" %numfilesproc
Note: See TracBrowser for help on using the repository browser.