Bug 3326: Work around Zebra's handling of & entities
authorJared Camins-Esakov <jcamins@bywatersolutions.com>
Tue, 15 Mar 2011 02:14:19 +0000 (22:14 -0400)
committerChris Nighswonger <chris.nighswonger@gmail.com>
Tue, 22 Mar 2011 21:21:13 +0000 (17:21 -0400)
When using XSLT mode, the OPAC results display will show "&amp;" instead of "&"
when Zebra is indexing in XML mode. This patch works around this by replacing
"&amp;" with "&" and then extends the previous fix to apply to all occurrences
of "& " instead of just the first.

Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
(cherry picked from commit d52f3680f482a42cc98ad9810c011c8775d9b3ee)

Signed-off-by: Chris Nighswonger <chris.nighswonger@gmail.com>
C4/Search.pm
C4/XSLT.pm

index dd76f4f..e8e0124 100644 (file)
@@ -1685,7 +1685,9 @@ sub searchResults {
             # FIXME note that XSLTResultsDisplay (use of XSLT to format staff interface bib search results)
             # is not implemented yet
             $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, 'Results', 
-                                                                $search_context);
+                                                                $search_context, 1);
+                # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs
+
         }
 
         # last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
index 4b6a99c..e63ecaf 100644 (file)
@@ -120,7 +120,7 @@ sub getAuthorisedValues4MARCSubfields {
 my $stylesheet;
 
 sub XSLTParse4Display {
-    my ( $biblionumber, $orig_record, $xsl_suffix, $interface ) = @_;
+    my ( $biblionumber, $orig_record, $xsl_suffix, $interface, $fixamps ) = @_;
     $interface = 'opac' unless $interface;
     # grab the XML, run it through our stylesheet, push it out to the browser
     my $record = transformMARCXML4XSLT($biblionumber, $orig_record);
@@ -138,8 +138,11 @@ sub XSLTParse4Display {
     }
     $sysxml .= "</sysprefs>\n";
     $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/;
+    if ($fixamps) { # We need to correct the ampersand entities that Zebra outputs
+        $xmlrecord =~ s/\&amp;/\&/g;
+    }
     $xmlrecord =~ s/\& /\&amp\; /;
-    $xmlrecord=~ s/\&amp\;amp\; /\&amp\; /;
+    $xmlrecord =~ s/\&amp\;amp\; /\&amp\; /;
 
     my $parser = XML::LibXML->new();
     # don't die when you find &, >, etc