Subject: | XML::LibXSLT-1.94 does not support EXSLT extensions |
I have pretty recent Perl version installed on my
OS X machine
% uname -a
Darwin X-maci 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64
as follows
% /$path/perl -v
This is perl 5, version 20, subversion 2 (v5.20.2) built for darwin-thread-multi-2level
Copyright ....
I also have recent version of libXSLT installed as follows
% /$path/perl -MXML::LibXSLT -le 'print $XML::LibXSLT::VERSION'
1.94
and I also get
% /$path/perl -MXML::LibXSLT -le 'print XML::LibXSLT::HAVE_EXSLT()'
1
Essentially, I am trying to access the EXSL extensions (`exsl:date-year(),exsl:document`) in my XSL file.
I get this error message whenever I try to use the extension(s)
xmlXPathCompOpEval: function year not found
Unregistered function
xmlXPathCompiledEval: evaluation failed
runtime error: file trans.xsl line 14 element value-of
XPath evaluation returned no result.
at Transform.pl line 43.
Is this a known problem with above OSX + Perl + libXSLT version combination ?
Relevant Code:
1) Perl file
use strict;
use warnings;
use File::Path;
use File::Spec;
use File::Basename;
use XML::LibXSLT;
use XML::LibXML;
use Getopt::Std;
my $isfile;
my ($xmlfile,$xsltfile,$samplefile) = qw/ Example.xml trans.xsl sample.xml/;
my %opts = ();
getopts('o:',\%opts);
my $outPath = $opts{'o'};
die "File not specified" if !defined($outPath);
if(-f $samplefile)
{
$isfile = "true";
print "File is present\n";
}
else
{
$isfile = "false";
print "File is absent\n";
}
my %args = ( "isfile" => $isfile,"outpath" => $outPath, );
my $xslt = XML::LibXSLT->new;
my $stylesheet = $xslt->parse_stylesheet_file($xsltfile);
my $security = XML::LibXSLT::Security->new();
$security->register_callback( read_file => sub { return 1;} );
$security->register_callback( write_file => sub { return 1;} );
$security->register_callback( create_dir => sub { return 1;} );
$stylesheet->security_callbacks( $security );
XML::LibXSLT->register_function("urn:foo", "bar",\&invalue);
my $results = $stylesheet->transform_file($xmlfile,XML::LibXSLT::xpath_to_string(%{args}));
sub invalue
{
my $var = shift;
return $var + 2;
}
0;
2) XSL file
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:exsl="http://exslt.org/common"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:foo="urn:foo"
extension-element-prefixes="exsl date">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" media-type="text/xml"/>
<xsl:param name="isfile"/>
<xsl:param name="outpath"/>
<xsl:variable name="current-year">
<xsl:value-of select="date:year()"/>
</xsl:variable>
<xsl:template match="/">
<xsl:if test="$isfile = 'true'">
<exsl:document href = "{$outpath}" method="xml" version="1.0" encoding="UTF-8" indent="yes">
Article:- <xsl:value-of select="exsl:node-set(/Article/Title)|exsl:node-set(/Article/Title)/@context"/>
Authors:- <xsl:apply-templates select="/Article/Authors/Author"/>
Perl function Output :- <xsl:value-of select="foo:bar(234)"/>
</exsl:document>
</xsl:if>
</xsl:template>
</xsl:stylesheet>