Perl 最好的 XSLT 引擎是什么? [英] What is the best XSLT engine for Perl?

查看:32
本文介绍了Perl 最好的 XSLT 引擎是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道有哪些 XSLT 引擎可以很好地与 Perl 配合使用.

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

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

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

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

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

谢谢.

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

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.

推荐答案

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

First mistake - search on CPAN, not Google :)

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

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.

令人不安的是,最佳答案(或至少是最佳答案之一)出现在结果的第四页 :( 正如其他人所建议的那样,XML::LibXSLT 很健壮,可以胜任:

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

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

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

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!).

  use XML::LibXSLT::Easy;

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

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

这篇关于Perl 最好的 XSLT 引擎是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆