NAME
XML::LibXSLT - Interface to the gnome libxslt library
SYNOPSIS
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);
DESCRIPTION
This module is an interface to the gnome project's libxslt. This is an extremely good XSLT engine, highly compliant and also very fast. I have tests showing this to be more than twice as fast as Sablotron.
OPTIONS
When calling new()
, the following options are available (passed in as a hash of key/value pairs):
- error_handler
-
A subroutine reference or function name that is called whenever an XSLT processsing error occurs. Note that this is not the same as an XML parsing error - for that see XML::LibXSLT.
API
The following methods are available on the new XML::LibXSLT object:
parse_stylesheet($doc)
$doc
here is an XML::LibXML::Document object (see XML::LibXML) representing an XSLT file. This method will return a XML::LibXSLT::Stylesheet object, or undef on failure.
XML::LibXSLT::Stylesheet
The main API is on the stylesheet, though it is fairly minimal.
One of the main advantages of XML::LibXSLT is that you have a generic stylesheet object which you call the transform() method passing in a document to transform. This allows you to have multiple transformations happen with one stylesheet without requiring a reparse.
transform($doc)
Transforms the passed in XML::LibXML::Document object, and returns a new XML::LibXML::Document.
output_string($result)
Returns a scalar that is the XSLT rendering of the XML::LibXML::Document object using the desired output format (specified in the xsl:output tag in the stylesheet). Note that you can also call $result->toString, but that will *always* output the document in XML format, and in UTF8, which may not be what you asked for in the xsl:output tag.
output_fh($result, $fh)
Outputs the result to the filehandle given in $fh
.
output_file($result, $filename)
Outputs the result to the file named in $filename
.
BENCHMARK
Included in the distribution is a simple benchmark script, which has two drivers - one for LibXSLT and one for Sablotron. The benchmark requires the testcases files from the XSLTMark distribution which you can find at http://www.datapower.com/XSLTMark/
Put the testcases directory in the directory created by this distribution, and then run:
perl benchmark.pl -h
to get a list of options.
The benchmark requires XML::XPath at the moment, but I hope to factor that out of the equation fairly soon. It also requires Time::HiRes, which I could be persuaded to factor out, replacing it with Benchmark.pm, but I haven't done so yet.
I would love to get drivers for XML::XSLT and XML::Transformiix, if you would like to contribute them. Also if you get this running on Win32, I'd love to get a driver for MSXSLT via OLE, to see what we can do against those Redmond boys!
AUTHOR
Matt Sergeant, matt@sergeant.org
Copyright 2001, AxKit.com Ltd. All rights reserved.
SEE ALSO
XML::LibXML