<<

NAME

Koha::XSLT::Base - Facilitate use of XSLT transformations

SYNOPSIS

    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);

DESCRIPTION

    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.

METHODS

new

    Create handler object

transform

    Run transformation for specific string and stylesheet

refresh

    Allow to reload stylesheets when transforming again

PROPERTIES

err

    Error code (see list of ERROR CODES)

do_not_return_source

    If true, transform returns undef on failure. By default, it returns the
    original string passed. Errors are reported as described.

print_warns

    If set, print error messages to STDERR. False by default.

ERROR CODES

Error XSLTH_ERR_NO_FILE

    No XSLT file passed

Error XSLTH_ERR_FILE_NOT_FOUND

    XSLT file not found

Error XSLTH_ERR_LOADING

    Error while loading stylesheet xml: [optional warnings]

Error XSLTH_ERR_PARSING_CODE

    Error while parsing stylesheet: [optional warnings]

Error XSLTH_ERR_PARSING_DATA

    Error while parsing input: [optional warnings]

Error XSLTH_ERR_TRANSFORMING

    Error while transforming input: [optional warnings]

Error XSLTH_NO_STRING_PASSED

    No string to transform

INTERNALS

    For documentation purposes. You are not encouraged to access them.

last_xsltfile

    Contains the last successfully executed XSLT filename

xslt_hash

    Hash reference to loaded stylesheets

ADDITIONAL COMMENTS

new

    my $xslt_engine = Koha::XSLT::Base->new;

transform

    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.

refresh

    $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.

AUTHOR

    Marcel de Rooy, Rijksmuseum Netherlands
    David Cook, Prosentient Systems

<<