Koha::XSLT_Handler - Facilitate use of XSLT transformations
use Koha::XSLT_Handler; my $xslt_engine = Koha::XSLT_Handler->new; my $output = $xslt_engine->transform($xml, $xsltfilename); my $err= $xslt_engine->err; # error number my $errstr= $xslt_engine->errstr; # error message $xslt_engine->refresh($xsltfilename);
A XSLT handler object on top of LibXML and LibXSLT, allowing you to run XSLT stylesheets repeatedly without loading them again. Errors occurring during loading, parsing or transforming are reported via the err and errstr attributes. Reloading XSLT files can be done with the refresh method.
Create handler object (via Class::Accessor)
Run transformation for specific string and stylesheet
Allow to reload stylesheets when transforming again
Error number (see list of ERROR CODES)
Error message
If true, transform returns undef on failure. By default, it returns the original string passed. Errors are reported as described.
If set, print error messages to STDERR. True by default.
No XSLT file passed
XSLT file not found
Error while loading stylesheet xml: [furter information]
Error while parsing stylesheet: [furter information]
Error while parsing input: [furter information]
Error while transforming input: [furter information]
No string to transform
For documentation purposes. You are not encouraged to access them.
Contains the last successfully executed XSLT filename
Hash reference to loaded stylesheets
my $output= $xslt_engine->transform( $xml, $xsltfilename ); if( $xslt_engine->err ) { #decide what to do on failure.. } my $output2= $xslt_engine->transform( $xml2 ); Pass a xml string and a fully qualified path of a XSLT file. Instead of a filename, you may also pass a URL. If you do not pass a filename, the last file used is assumed. Returns the transformed string. Check the error number in err to know if something went wrong. In that case do_not_return_source did determine the return value.
$xslt_engine->refresh; $xslt_engine->refresh( $xsltfilename ); Pass a file for an individual refresh or no file to refresh all. Refresh returns the number of items affected. What we actually do, is just clear the internal cache for reloading next time when transform is called. The return value is mainly theoretical. Since this is supposed to work always(...), there is no actual need to test it. Note that refresh does also clear the error information.
Marcel de Rooy, Rijksmuseum Netherlands