BatchXSLT - Batch processing of XML files with Xalan


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...


java 

See Also