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