Lines 40-47
an XML format such as OAI DC, RSS2, MARCXML, or MODS.
Link Here
|
40 |
use CGI qw ( -utf8 ); |
40 |
use CGI qw ( -utf8 ); |
41 |
use C4::Context; |
41 |
use C4::Context; |
42 |
use C4::Biblio; |
42 |
use C4::Biblio; |
43 |
use XML::LibXML; |
43 |
use Koha::XSLT_Handler; |
44 |
use XML::LibXSLT; |
|
|
45 |
|
44 |
|
46 |
my $cgi = CGI->new(); |
45 |
my $cgi = CGI->new(); |
47 |
binmode(STDOUT, ":encoding(UTF-8)"); #output as utf8 |
46 |
binmode(STDOUT, ":encoding(UTF-8)"); #output as utf8 |
Lines 138-155
if (not defined $format) {
Link Here
|
138 |
exit 0; |
137 |
exit 0; |
139 |
} |
138 |
} |
140 |
|
139 |
|
141 |
my $transformer = get_transformer($format, $format_to_stylesheet_map, $format_info); |
140 |
my $xslt_file = get_xslt_file( $format, $format_to_stylesheet_map, $format_info ); |
142 |
unless (defined $transformer) { |
141 |
unless( defined $xslt_file ) { |
143 |
print $cgi->header( -status => '406 invalid format requested' ); |
142 |
print $cgi->header( -status => '406 invalid format requested' ); |
144 |
exit 0; |
143 |
exit 0; |
145 |
} |
144 |
} |
146 |
my $parser = XML::LibXML->new(); |
145 |
my $xslt_engine = Koha::XSLT_Handler->new; |
147 |
my $record_dom = $parser->parse_string( $marcxml ); |
146 |
$content = $xslt_engine->transform({ |
148 |
$record_dom = $transformer->transform( $record_dom ); |
147 |
xml => $marcxml, |
149 |
$content = $transformer->output_as_chars( $record_dom ); |
148 |
file => $xslt_file, |
|
|
149 |
}); |
150 |
}; |
150 |
}; |
151 |
if ($@) { |
151 |
if ($@) { |
152 |
print $cgi->header( -status => '500 internal error ' . $@->code() . ": " . $@->message() ); |
152 |
print $cgi->header( -status => '500 internal error ' . $@ ); |
153 |
exit 0; |
153 |
exit 0; |
154 |
} |
154 |
} |
155 |
|
155 |
|
Lines 193-199
sub emit_formats {
Link Here
|
193 |
} |
193 |
} |
194 |
|
194 |
|
195 |
|
195 |
|
196 |
sub get_transformer { |
196 |
sub get_xslt_file { |
197 |
my ($format, $format_to_stylesheet_map, $format_info) = @_; |
197 |
my ($format, $format_to_stylesheet_map, $format_info) = @_; |
198 |
$format = lc $format; |
198 |
$format = lc $format; |
199 |
|
199 |
|
Lines 204-215
sub get_transformer {
Link Here
|
204 |
"/prog/en/xslt/" . |
204 |
"/prog/en/xslt/" . |
205 |
$format_to_stylesheet_map->{$marcflavour}->{$format}; |
205 |
$format_to_stylesheet_map->{$marcflavour}->{$format}; |
206 |
|
206 |
|
207 |
my $parser = XML::LibXML->new(); |
207 |
return $xslt_file; |
208 |
my $xslt = XML::LibXSLT->new(); |
|
|
209 |
my $style_doc = $parser->parse_file( $xslt_file ); |
210 |
my $stylesheet = $xslt->parse_stylesheet( $style_doc ); |
211 |
|
212 |
return $stylesheet; |
213 |
} |
208 |
} |
214 |
|
209 |
|
215 |
=head1 AUTHOR |
210 |
=head1 AUTHOR |
216 |
- |
|
|