@@ -, +, @@ template --- C4/MarcModificationTemplates.pm | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) --- a/C4/MarcModificationTemplates.pm +++ a/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__ --