Perl and XSLT
By Adrian Sutton
Following my complaints yesterday I think I’ve finally managed to get XSLT working correctly in perl. The secret: ignore the obvious choice (XML::XSLT) and use XML::LibXML and XML::LibXSLT in combination. Then use fink heavily as well. Try to avoid using CPAN or installing perl modules by hand until you don’t have a choice. Step 1: Install expat, libxml, libxslt and sablotron using fink. Install anything else that looks vaguely XML related while you’re there too. Step 2: Using fink, install every XML or XSLT related perl package you can find. Step 3: Using CPAN run: install XML::LibXML. Step 4: Using CPAN run: install XML::LibXSLT Then use code similar to: `my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); my $stylesheet = $xslt->parse_stylesheet_file($xsl);
my $source_doc = $parser->parse_file($xmlfile); my $result = $stylesheet->transform($source_doc);
print $stylesheet->output_string($result);` The problems that need to be fixed in order to make this easier in future:
- CPAN isn’t capable (at least in these cases) of compiling the pure C dependencies of perl libraries. This means that if you don’t have something like expat installed, CPAN just bails out of the install with a long series of error messages, none of which make it obvious what went wrong.
- CPAN’s dependency list for XML::LibXSLT doesn’t include XML::LibXML despite the fact that it won’t compile without it.
- A bunch of perl modules depend on expat, but when expat is installed by fink they can’t find it and require that you pass EXPATLIBPATH=… and EXPATINCPATH=… in to the perl Makefile.PL stage. Unfortunately, it doesn’t provide instructions for doing this when using CPAN to install. fink however correctly builds those packages. You can, in theory, also build them by hand but for some reason the tests failed when I did it that way. Oh well, back to actually getting some work done instead of fighting my tools.