parse_orcid.pl 869 Bytes
#!/usr/bin/perl -w

#requires packages libxml-libxslt-perl, libxml-xpath-perl, libxml-perl

# (1) quit unless we have the correct number of command-line args
$num_args = $#ARGV + 1;
if ($num_args != 1) {
    print "\nUsage: parse_orcid.pl path/to/filename.xml\n";
    exit;
}


$filename=$ARGV[0];
unless (-e $filename) { 
    print "\nFile: $filename doesn't exist!\n"; 
    exit;
}

use XML::LibXML;
use XML::LibXSLT;
use File::Spec;

my ($volume, $directory, $file) = File::Spec->splitpath(__FILE__);

XML::LibXSLT->max_depth(1000);

my $xslt = XML::LibXSLT->new();

my $source = XML::LibXML->load_xml(location => $filename);
my $style_doc = XML::LibXML->load_xml(location=>$directory.'/orcid-map.xslt', no_cdata=>1);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);

print $stylesheet->output_as_bytes($results);