我最近在我的
OS机
% 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如下所示
% /$path/perl -v
This is perl 5, version 20, subversion 2 (v5.20.2) built for darwin-thread-multi-2level
Copyright ....我还安装了最新版本的libXSLT,如下所示
% /$path/perl -MXML::LibXSLT -le 'print $XML::LibXSLT::VERSION'
1.94我也得到了
% /$path/perl -MXML::LibXSLT -le 'print XML::LibXSLT::HAVE_EXSLT()'
1我已经要求这个问题解释我的用例。本质上,我试图访问我的XSL文件中的EXSL扩展(exsl:date-year(),exsl:document)。因为当时我有一个相当旧的Perl和libXSLT版本,所以没有解决这个问题的方法。
现在,我已经更新了Perl和libXSLT版本,每当我尝试使用扩展时仍然会收到此错误消息。
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.这是上述OSX + Perl + libXSLT版本组合的已知问题吗?
PS:有趣的是,此页没有提到darwin-thread-multi-2level for version 5.20.2的结果。
更新
1) Perl文件
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文件
<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">
<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>发布于 2016-11-28 09:06:56
请运行以下样式表(对任何输入)并报告结果:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<test>
<proc>
<xsl:value-of select="system-property('xsl:vendor')"/>
</proc>
<year>
<xsl:value-of select="function-available('date:year')"/>
</year>
</test>
</xsl:template>
</xsl:stylesheet>没有答案,但需要空间。
https://stackoverflow.com/questions/40838313
复制相似问题