views:

1070

answers:

4

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

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.

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.

+3  A: 

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.

aku
+3  A: 

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

moritz
+17  A: 

First mistake - search on CPAN, not 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.

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 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" );
Penfold
+1  A: 

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

derby