Koha::XSLT::Base - Facilitate use of XSLT transformations
use Koha::XSLT::Base; my $xslt_engine = Koha::XSLT::Base->new; my $output = $xslt_engine->transform($xml, $xsltfilename); $output = $xslt_engine->transform({ xml => $xml, file => $file }); $output = $xslt_engine->transform({ xml => $xml, code => $code }); my $err= $xslt_engine->err; # error code $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 attribute. Reloading XSLT files can be done with the refresh method. The module refers to a (temporary) helper module Koha::XSLT::HTTPS that resolves issues in libxml2/libxslt for https references.
Create handler object
Run transformation for specific string and stylesheet
Allow to reload stylesheets when transforming again
Error code (see list of ERROR CODES)
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. False by default.
No XSLT file passed
XSLT file not found
Error while loading stylesheet xml: [optional warnings]
Error while parsing stylesheet: [optional warnings]
Error while parsing input: [optional warnings]
Error while transforming input: [optional warnings]
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 $xslt_engine = Koha::XSLT::Base->new;
my $output= $xslt_engine->transform( $xml, $xsltfilename, [$format] ); #Alternatively: #$output = $xslt_engine->transform({ xml => $xml, file => $file, [parameters => $parameters], [format => ['chars'|'bytes'|'xmldoc']] }); #$output = $xslt_engine->transform({ xml => $xml, code => $code, [parameters => $parameters], [format => ['chars'|'bytes'|'xmldoc']] }); 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. You may also pass the contents of a xsl file as a string like $code above. If you do not pass a filename, the last file used is assumed. Normally returns the transformed string; if you pass format => 'xmldoc' in the hash format, it returns a xml document object. 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 David Cook, Prosentient Systems