From 99366cb99b8ec4cffdb5766565420be129d86b48 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 13 Aug 2014 16:10:27 +0200 Subject: [PATCH] Bug 12754: Perform the actual XSLT action for marc mod template Content-Type: text/plain; charset=utf-8 This patch modifies MarcModificationTemplates.pm. A local subroutine _RunXSLTAction is added to perform the actual xslt transformation using the XSLTHandler object. Test plan: Add some XSLT actions to a marc mod template. Run Stage for Import and select the correct marc mod template. Check your staged records for the expected changes (you can also view these reservoir records in Cataloging search). --- C4/MarcModificationTemplates.pm | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm index a470066..d3d60e4 100644 --- a/C4/MarcModificationTemplates.pm +++ b/C4/MarcModificationTemplates.pm @@ -23,11 +23,14 @@ use DateTime; use C4::Context; use Koha::SimpleMARC; +use Koha::XSLT_Handler; use vars qw($VERSION @ISA @EXPORT); use constant DEBUG => 0; +my $engine; #XSLT Handler object + BEGIN { $VERSION = 1.00; # set the version for version checking @ISA = qw(Exporter); @@ -47,6 +50,7 @@ BEGIN { &ModifyRecordsWithTemplate &ModifyRecordWithTemplate ); + $engine=Koha::XSLT_Handler->new(); } @@ -508,6 +512,7 @@ sub ModifyRecordWithTemplate { foreach my $a ( @actions ) { my $action = $a->{'action'}; + my $field_number = $a->{'field_number'}; my $from_field = $a->{'from_field'}; my $from_subfield = $a->{'from_subfield'}; @@ -536,6 +541,8 @@ sub ModifyRecordWithTemplate { ? ( undef, $field_value ) : () ); + } elsif ( $action eq 'run_xslt' ) { + #nothing to do } else { push @params, ( $field_value @@ -607,11 +614,27 @@ sub ModifyRecordWithTemplate { elsif ( $action eq 'delete_field' ) { delete_field(@params); } + elsif ( $action eq 'run_xslt' ) { + _RunXSLTAction ( $record, $a->{run_xslt} ); + } } warn( $record->as_formatted() ) if DEBUG >= 10; } } + +sub _RunXSLTAction { + my ( $record, $xsl )= @_; + my $xml= $engine->transform($record->as_xml, $xsl ); + if ( $engine->err ) { + warn "XSLT marc mod template action failed with $xsl"; + } else { + my $newrecord= MARC::Record->new_from_xml($xml, 'UTF-8'); + $record->delete_fields( $record->fields() ); #clear all fields + $record->append_fields( $newrecord->fields() ); + } +} + 1; __END__ -- 1.7.7.6