<<

NAME

Koha::XSLT_Handler - Facilitate use of XSLT transformations

SYNOPSIS

    use Koha::XSLT_Handler;
    my $xslt_engine = Koha::XSLT_Handler->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 number
    my $errstr= $xslt_engine->errstr; # error message
    $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 and errstr attributes.
    Reloading XSLT files can be done with the refresh method.

METHODS

new

    Create handler object (via Class::Accessor)

transform

    Run transformation for specific string and stylesheet

refresh

    Allow to reload stylesheets when transforming again

PROPERTIES

err

    Error number (see list of ERROR CODES)

errstr

    Error message

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. True by default.

ERROR CODES

Error 1

    No XSLT file passed

Error 2

    XSLT file not found

Error 3

    Error while loading stylesheet xml: [furter information]

Error 4

    Error while parsing stylesheet: [furter information]

Error 5

    Error while parsing input: [furter information]

Error 6

    Error while transforming input: [furter information]

Error 7

    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

transform

    my $output= $xslt_engine->transform( $xml, $xsltfilename );
    #Alternatively:
    #$output = $xslt_engine->transform({ xml => $xml, file => $file, [parameters => $parameters] });
    #$output = $xslt_engine->transform({ xml => $xml, code => $code, [parameters => $parameters] });
    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.
    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.

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

<<