Skip to content

Instantly share code, notes, and snippets.

@jnbek
Created December 22, 2016 00:49
Show Gist options
  • Save jnbek/9a12a2b8964e51456e2b074f71ac3ace to your computer and use it in GitHub Desktop.
Save jnbek/9a12a2b8964e51456e2b074f71ac3ace to your computer and use it in GitHub Desktop.
xsltproc vs perl
#!/usr/bin/env perl
use strict;
use warnings;
use XML::LibXSLT;
use XML::LibXML;
use Data::Dumper;
(bless {}, __PACKAGE__)->main();
sub main {
my $self = shift;
my $file = $ARGV[2];
my $dtd_text = do { local( @ARGV, $/ ) = $file ; <> } ;
my $dtd = XML::LibXML::Dtd->parse_string($dtd_text);
my $xslt = XML::LibXSLT->new();
my $source = XML::LibXML->load_xml(location => $ARGV[0]);
#$source->validate($dtd);
my $style_doc = XML::LibXML->load_xml(location=> $ARGV[1], no_cdata=>1);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
print $stylesheet->output_as_bytes($results);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment