第一個錯誤 - search on CPAN,不穀歌:)
這拋出了一堆結果,但確實突出顯示了CPAN的問題,有多個解決方案,並不總是清楚哪些工作,已被放棄,是壞了,慢還是其他。
而令人不安的是,最好的答案(或至少是最好的之一)頁面上出現的結果:(正如其他人所建議的,XML::LibXSLT是穩健和沒有工作的:
use XML::LibXSLT;
use XML::LibXML;
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
my $source = $parser->parse_file('foo.xml');
my $style_doc = $parser->parse_file('bar.xsl');
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($source);
print $stylesheet->output_string($results);
如果你不想做任何奇特的事情,那就是XML::LibXSLT::Easy,它基本上只是在一個方法調用中包裝了上述內容(並且在幕後使用Moose做了一堆聰明的東西。 )
use XML::LibXSLT::Easy;
my $p = XML::LibXSLT::Easy->new;
my $output = $p->process(xml => "foo.xml", xsl => "foo.xsl");