source: CommonItems/trunk/XSLT/one-off_XSLT/run_oneoff_xslt.py @ 1136

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/CommonItems/trunk/XSLT/one-off_XSLT/run_oneoff_xslt.py@1136
Revision 1136, 1.1 KB checked in by selatham, 14 years ago (diff)

added script for running any xslt over dir of xml files

RevLine 
[1136]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.
7"""
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")
12
13xslt_name = sys.argv[1]
14
15if len(sys.argv) ==2:                   #if no filenames are specified use current dir
16        filenames = os.listdir(os.curdir)
17else:
18        filenames = sys.argv[2:]
19
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
29
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.