[Koha-patches] [PATCH] Avoid XSLT stylesheet building for each biblio record to transform

Frederic Demians f.demians at tamil.fr
Thu Feb 5 08:26:13 CET 2009


In XSLT.pm, put XSLT stylesheet object in a session variable in order
to avoid to build it for each biblio to parse: useful on search
result page.
---
 C4/XSLT.pm |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index 3c781d2..06025cf 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -106,6 +106,8 @@ sub getAuthorisedValues4MARCSubfields {
     return \@results;
 }
 
+my $stylesheet;
+
 sub XSLTParse4Display {
     my ($biblionumber,$xslfile) = @_;
     # grab the XML, run it through our stylesheet, push it out to the browser
@@ -116,10 +118,12 @@ sub XSLTParse4Display {
     my $parser = XML::LibXML->new();
     # don't die when you find &, >, etc
     $parser->recover_silently(1);
-    my $xslt = XML::LibXSLT->new();
     my $source = $parser->parse_string($xmlrecord);
-    my $style_doc = $parser->parse_file($xslfile);
-    my $stylesheet = $xslt->parse_stylesheet($style_doc);
+    unless ( $stylesheet ) {
+        my $xslt = XML::LibXSLT->new();
+        my $style_doc = $parser->parse_file($xslfile);
+        $stylesheet = $xslt->parse_stylesheet($style_doc);
+    }
     my $results = $stylesheet->transform($source);
     my $newxmlrecord = $stylesheet->output_string($results);
     return $newxmlrecord;
-- 
1.5.5.GIT




More information about the Koha-patches mailing list