#use strict; use Win32::OLE; if ($#ARGV < 1) { print "Usage: $0 [ ...] []\n"; print "Processes file using in sequence the stylesheets\n"; print ", ... and write output in file\n"; print " (or stdout if no third argument is given).\n"; exit; } $aInputFile = $ARGV[0]; if ($#ARGV >= 2) { $aOutputFile = $ARGV[$#ARGV]; if ($aOutputFile =~ /\.xsl$/i) { $aOutputFile = ''; print STDERR "Output is not written into an $ARGV[$#ARGV]!\n"; } } # load input file into DOM Document if (!(-f $aInputFile)) {die "Cannot open file $aInputFile for reading\n";} my $aInputDoc = Win32::OLE->new('Msxml2.DOMDocument'); if ($aInputDoc eq undef) {die "Could not load Msxml2.DOMDocument\n";} $aInputDoc->{'async'} = 0; $aInputDoc->load($aInputFile); # generate text my $xsldoc = Win32::OLE->new('Msxml2.DOMDocument'); for ($iXSL = 1; ($iXSL < $#ARGV) || ($iXSL == 1); $iXSL++) { $aXSLFile = $ARGV[$iXSL]; if (!(-f $aXSLFile)) {die "Cannot open file $aXSLFile for reading\n";} $xsldoc->{'async'} = 0; $xsldoc->load($aXSLFile); $aOutputText = $aInputDoc->transformNode($xsldoc); $aInputDoc->loadXML($aOutputText); } # write output if ($aOutputFile ne '') { open(FILE,">$aOutputFile") or die "Cannot write to file $aOutputFile\n";; print FILE $aOutputText; close(FILE); } else { print $aOutputText; }