簡體   English   中英

具有libXSLT 1.94錯誤的Perl 5.20.2

[英]Perl 5.20.2 with libXSLT 1.94 error

我已經安裝了Perl最新版本

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

我已經問過這個問題來解釋我的用例。 本質上,我試圖訪問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:有趣的是, 此頁面未提及version 5.20.2 darwin-thread-multi-2level的結果。

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>

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

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM