apache Perl 最好的 XSLT 引擎是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/156683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:47:41  来源:igfitidea点击:

What is the best XSLT engine for Perl?

perlapachepdfxhtmlxslt

提问by David Ameller

I would like to know what of the many XSLT engines out there works well with Perl.

我想知道在许多 XSLT 引擎中,哪些引擎与 Perl 配合得很好。

I will use Apache (2.0) and Perl, and I want to obtain PDFs and XHTMLs.

我将使用 Apache (2.0) 和 Perl,我想获取 PDF 和 XHTML。

I'm new to this kind of projects so any comment or suggestion will be welcome.

我是此类项目的新手,因此欢迎提出任何意见或建议。

Thanks.

谢谢。



Doing a simple search on Google I found a lot and I suppose that there are to many more.

在谷歌上做一个简单的搜索,我发现了很多,我想还有更多。

Any comment on your experiences will be welcome.

欢迎对您的经历发表任何评论。

回答by Penfold

First mistake - search on CPAN, not Google :)

第一个错误 -在 CPAN 上搜索,而不是 Google :)

This throws up a bunch of results, but does rather highlight the problem of CPAN, that there's more than one solution, and it's not always clear which ones work, have been abandoned, are broken, slow or whatever.

这会产生一堆结果,但确实突出了 CPAN 的问题,即有多个解决方案,并且并不总是清楚哪些有效、已被放弃、已损坏、缓慢或其他任何问题。

And disturbingly, the best answer (or at least, one of the best) comes up on page fourof the results :( As other folks have suggested, XML::LibXSLTis robust and does the job:

令人不安的是,最佳答案(或至少是最佳答案之一)出现在结果的第四页:( 正如其他人所建议的那样,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);

If you want to output results to a file then add this

如果要将结果输出到文件,请添加此

#create output file
open(my $output_xml_file_name, '>', 'test.xml');
print $output_xml_file_name "$results";

If you don't want to do anything fancy, though, there's XML::LibXSLT::Easy, which essentially just wraps the above in one method call (and does a bunch of clever stuff behind the scenes using Moose. Check the source for an education!).

但是,如果您不想做任何花哨的事情,可以使用XML::LibXSLT::Easy,它本质上只是将上述内容包装在一个方法调用中(并且在幕后使用Moose做了一堆聪明的事情。检查源教育!)。

  use XML::LibXSLT::Easy;

  my $p = XML::LibXSLT::Easy->new;

  my $output = $p->process( xml => "foo.xml", xsl => "foo.xsl" );

回答by moritz

So far I'm very satisfied with XML::LibXMLfor non-xslt tasks, and its documentation points to XML::LibXSLT, which looks quite nice, but I have no experience with it so far

到目前为止,我对非 xslt 任务的XML::LibXML非常满意,它的文档指向XML::LibXSLT,这看起来很不错,但到目前为止我还没有经验

回答by aku

Can't really say which is the best solution because I didn't have a chance to try them all.
But I can recommend you to try Perl module LibXSLT.
It's an interface to the gnome libxslt library. I used it on one of my recent project was satisfied with it.

不能说哪个是最好的解决方案,因为我没有机会全部尝试。
但我可以推荐您尝试 Perl 模块LibXSLT
它是 gnome libxslt 库的接口。我在最近的一个项目中使用了它,对此我感到很满意。

回答by derby

You don't say what OS but for most *nix platforms, XML::LibXMLis going to be the easiest to use and install.

您不会说是什么操作系统,但对于大多数 *nix 平台,XML::LibXML将是最容易使用和安装的。

回答by Paul Sweatte

Here are a few Perl libraries intended to replace XSLT:

以下是一些旨在替代 XSLT 的 Perl 库: