#! /usr/bin/perl -w #-------------------------------------------------------------------------- # Transform an XML document with an XSLT stylesheet #-------------------------------------------------------------------------- use strict; use File::Basename; use FileHandle; use Getopt::Long; use XML::LibXML; use XML::LibXSLT; my $basename = basename $0; my $usage = <new(); my $xslt = XML::LibXSLT->new(); # source is the XML document to be transformed my $source = $parser->parse_file($opts{xml}); # style_doc is the XSLT stylesheet my $style_doc = $parser->parse_file($opts{xsl}); my $stylesheet = $xslt->parse_stylesheet($style_doc); # results is the resulting XML::LibXML::Document object my $results = $stylesheet->transform($source); # Output the result somewhere my $fh = FileHandle->new($opts{output}); $stylesheet->output_fh($results, $fh);