2016-11-28 42 views
0

我有非常近的Perl版本我與1.94的libxslt錯誤的Perl 5.20.2

OS X計算機上安裝

% 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 

我已經問this question解釋我的使用情況。 本質上,我試圖訪問我的XSL文件中的EXSL擴展(exsl:date-year(),exsl:document)。由於當時我有一個漂亮的Perl和libXSLT版本,所以沒有解決這個問題。

現在我已經更新了我的Perl和的libxslt版本,仍然每當我試圖使用擴展(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. 

這是一個已知的問題,我得到這個錯誤信息上面OSX +的Perl +的libxslt版本組合?

PS: 有趣的是,this page沒有提及darwin-thread-multi-2levelversion 5.20.2的結果。

UPDATE

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> 
+0

您忘了提供產生該輸出的代碼和數據... – ikegami

+0

不確定它是否有所作爲,但'extension-element-prefixes =「exsl」'應該是'extension-element-prefixes = exsl date「'。 –

回答

0

請運行以下樣式表(在任何輸入),並報告結果:

<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> 

沒有答案,但需要的空間。

+0

腳本運行時不顯示任何結果。 ( – Recker

+0

)這很奇怪,請使用更新過的樣式表再試一次。 –

+0

我改變我的Perl腳本使用'output_as_bytes' API後得到了輸出,輸出是'libxslt'和'false'。 – Recker