#!/usr/bin/perl -w

# compile stylesheet once, run it on many xml inputs

use blib;
use XML::Xalan;
use Getopt::Long;

my %opts = ();
GetOptions(\%opts, 'xsl=s', 'suffix=s');

if (not exists $opts{xsl} or not exists $opts{suffix}
    or @ARGV < 2) {
    die <<"USAGE"
Usage: $0 -xsl xsl_file -suffix html *.xml
    -suffix: suffix to be appended to the output filenames
    -xsl   : stylesheet file
USAGE
}

my $p = new XML::Xalan;

$p->parse_stylesheet($opts{xsl});

for (@ARGV) {
    print "Transforming from $_ to $_.$opts{suffix}..\n";
    $p->transform_to_file($_, "$_.$opts{suffix}")
        or die $p->errstr;
}

