Jul
12
(2004)
BatchXSLT - Batch processing of XML files with Xalan
Filed under: Uncategorized. Tags: java.
I’m in the process of migrating a copy of the metadata records from CAREO into an XStreamDB database. As part of that process, I’m transforming all documents from various malformed IMS LOM versions to the clean IEEE LOM schema. I looked around for a batch tool, and didn’t find one that didn’t rely on VB or MSXML or something equally unusable for me. So, I rolled my own java command line utility, called “BatchXSLT”.
It’s so brain-dead simple to write a tool like this, that I’m SURE it exists already, and must be part of the Xalan distribution (buried somewhere? the sample tools didn’t appear to handle batching). The other Xalan batch tool I saw used a shell script which spawned the java process fresh for each xml doc. That’s just plain wasteful, so this one just uses one java process, and walks through the directory as required.
Anyway, with about half an hour of coding (over half of that spent googling), I had a working tool. It’s a simple utility, but it takes 3 parameters that make it pretty useful, so I thought I’d share it with the rest of the class, just in case…
I drop the .jar file into my /Library/Java/Extensions/ directory, so it’s available system-wide.
USAGE:
java BatchXSLT inputSource XSLTFile outputDirectory
inputSource: either a file or a directory containing files to be transformed. It will attempt to transform every file in a directory, but won’t recurse through nested directories (yet).
XSLTFile: the XSLT file to be used to direct the transformation
outputDirectory: the directory where you want to store the transformed files (it doesn’t overwrite the originals, but has to stick them someplace else) - it would probably be a Good Idea for this to be a different directory than the inputSource, so there isn’t any kind of recursive/destructive cycle going on….
Here’s what I typically call:
java BatchXSLT ~/temp/rawxml ~/Documents/XSLT/LRMv1p2p1-LOMv1p0.xsl ~/temp/transformedxml
Doing that will run through the ~4000 xml documents, transforming them into nice, valid IEEE LOMs.
The source code and compiled .jar is available for download, including an XCode project. download here.
Oh, and there isn’t any kind of license or anything for this BatchXSLT app or source code. Help yourself. Make it do whatever you need. I wouldn’t mind hearing from anyone who found it useful, though…
There is also no warranty of any kind… It works great for me, in my own little world and very specific use-case. I won’t guarantee that it won’t run amok and attempt to transform your kernel or swap file or something silly…
Comments
2 Responses to “BatchXSLT - Batch processing of XML files with Xalan”
Leave a Reply


We have developed our website in ASP ,we now want to allow the users to download an HTML file ,( convert it into XML) & store in the client PC & then allow the client to do batch uploading of XML files .
Can we use your script ( which is in Java)
what are the things we need to install on the server?
Thanks!!
It would be great ,if we can work it out with your script.
Your technical work is highly appreciable .
Thiru, I’m not sure what you’re wanting to do… The BatchXSLT code just takes a bunch of input files, mashes them through an XSLT, and writes out the output files. It should be possible to use that for anything, but I’d be surprised if ASP didn’t grok XSLT natively…