Lines 23-33
use DateTime;
Link Here
|
23 |
|
23 |
|
24 |
use C4::Context; |
24 |
use C4::Context; |
25 |
use Koha::SimpleMARC; |
25 |
use Koha::SimpleMARC; |
|
|
26 |
use Koha::XSLT_Handler; |
26 |
|
27 |
|
27 |
use vars qw($VERSION @ISA @EXPORT); |
28 |
use vars qw($VERSION @ISA @EXPORT); |
28 |
|
29 |
|
29 |
use constant DEBUG => 0; |
30 |
use constant DEBUG => 0; |
30 |
|
31 |
|
|
|
32 |
my $engine; #XSLT Handler object |
33 |
|
31 |
BEGIN { |
34 |
BEGIN { |
32 |
$VERSION = 1.00; # set the version for version checking |
35 |
$VERSION = 1.00; # set the version for version checking |
33 |
@ISA = qw(Exporter); |
36 |
@ISA = qw(Exporter); |
Lines 47-52
BEGIN {
Link Here
|
47 |
&ModifyRecordsWithTemplate |
50 |
&ModifyRecordsWithTemplate |
48 |
&ModifyRecordWithTemplate |
51 |
&ModifyRecordWithTemplate |
49 |
); |
52 |
); |
|
|
53 |
$engine=Koha::XSLT_Handler->new(); |
50 |
} |
54 |
} |
51 |
|
55 |
|
52 |
|
56 |
|
Lines 508-513
sub ModifyRecordWithTemplate {
Link Here
|
508 |
|
512 |
|
509 |
foreach my $a ( @actions ) { |
513 |
foreach my $a ( @actions ) { |
510 |
my $action = $a->{'action'}; |
514 |
my $action = $a->{'action'}; |
|
|
515 |
|
511 |
my $field_number = $a->{'field_number'}; |
516 |
my $field_number = $a->{'field_number'}; |
512 |
my $from_field = $a->{'from_field'}; |
517 |
my $from_field = $a->{'from_field'}; |
513 |
my $from_subfield = $a->{'from_subfield'}; |
518 |
my $from_subfield = $a->{'from_subfield'}; |
Lines 536-541
sub ModifyRecordWithTemplate {
Link Here
|
536 |
? ( undef, $field_value ) |
541 |
? ( undef, $field_value ) |
537 |
: () |
542 |
: () |
538 |
); |
543 |
); |
|
|
544 |
} elsif ( $action eq 'run_xslt' ) { |
545 |
#nothing to do |
539 |
} else { |
546 |
} else { |
540 |
push @params, |
547 |
push @params, |
541 |
( $field_value |
548 |
( $field_value |
Lines 607-617
sub ModifyRecordWithTemplate {
Link Here
|
607 |
elsif ( $action eq 'delete_field' ) { |
614 |
elsif ( $action eq 'delete_field' ) { |
608 |
delete_field(@params); |
615 |
delete_field(@params); |
609 |
} |
616 |
} |
|
|
617 |
elsif ( $action eq 'run_xslt' ) { |
618 |
_RunXSLTAction ( $record, $a->{run_xslt} ); |
619 |
} |
610 |
} |
620 |
} |
611 |
|
621 |
|
612 |
warn( $record->as_formatted() ) if DEBUG >= 10; |
622 |
warn( $record->as_formatted() ) if DEBUG >= 10; |
613 |
} |
623 |
} |
614 |
} |
624 |
} |
|
|
625 |
|
626 |
sub _RunXSLTAction { |
627 |
my ( $record, $xsl )= @_; |
628 |
my $xml= $engine->transform($record->as_xml, $xsl ); |
629 |
if ( $engine->err ) { |
630 |
warn "XSLT marc mod template action failed with $xsl"; |
631 |
} else { |
632 |
my $newrecord= MARC::Record->new_from_xml($xml, 'UTF-8'); |
633 |
$record->delete_fields( $record->fields() ); #clear all fields |
634 |
$record->append_fields( $newrecord->fields() ); |
635 |
} |
636 |
} |
637 |
|
615 |
1; |
638 |
1; |
616 |
__END__ |
639 |
__END__ |
617 |
|
640 |
|
618 |
- |
|
|