# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
-# $Id$
#
-use strict; use warnings; #FIXME: turn off warnings before release
+use strict;# use warnings; #FIXME: turn off warnings before release
# please specify in which methods a given module is used
use MARC::Record; # marc2marcxml, marcxml2marc, html2marc, changeEncoding
use MARC::File::XML; # marc2marcxml, marcxml2marc, html2marcxml, changeEncoding
use MARC::Crosswalk::DublinCore; # marc2dcxml
-#use MODS::Record; # marc2modsxml
+use Biblio::EndnoteStyle;
use Unicode::Normalize; # _entity_encode
+use XML::LibXSLT;
+use XML::LibXML;
use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g;
- shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
+$VERSION = 3.00;
@ISA = qw(Exporter);
# only export API methods
@EXPORT = qw(
+ &marc2endnote
&marc2marc
&marc2marcxml
&marcxml2marc
$crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 1 );
}
my $dcxml = $crosswalk->as_dublincore($marc_record_obj);
- return ($error,$dcxml);
+ my $dcxmlfinal = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ $dcxmlfinal .= "<metadata
+ xmlns=\"http://example.org/myapp/\"
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+ xsi:schemaLocation=\"http://example.org/myapp/ http://example.org/myapp/schema.xsd\"
+ xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
+ xmlns:dcterms=\"http://purl.org/dc/terms/\">";
+
+ foreach my $element ( $dcxml->elements() ) {
+ $dcxmlfinal.="<"."dc:".$element->name().">".$element->content()."</"."dc:".$element->name().">\n";
+ }
+ $dcxmlfinal .= "\n</metadata>";
+ return ($error,$dcxmlfinal);
}
=head2 marc2modsxml - Convert from ISO-2709 to MODS
=cut
sub marc2modsxml {
- use XML::XSLT;
- #use XML::LibXSLT;
my ($marc) = @_;
- my $error;
- my $marcxml;
-
- # open some files for testing
- open MARCBIG21MARC21SLIM,"/home/koha/head/koha/C4/MARC21slim2MODS3-1.xsl" or die $!;
- my $marcbig2marc21_slim; # = scalar (MARC21MARC8);
- foreach my $line (<MARCBIG21MARC21SLIM>) {
- $marcbig2marc21_slim .= $line;
- }
+ # grab the XML, run it through our stylesheet, push it out to the browser
+ my $xmlrecord = marc2marcxml($marc);
+ my $xslfile = C4::Context->config('intrahtdocs')."/prog/en/xslt/MARC21slim2MODS3-1.xsl";
+ my $parser = XML::LibXML->new();
+ my $xslt = XML::LibXSLT->new();
+ my $source = $parser->parse_string($xmlrecord);
+ my $style_doc = $parser->parse_file($xslfile);
+ my $stylesheet = $xslt->parse_stylesheet($style_doc);
+ my $results = $stylesheet->transform($source);
+ my $newxmlrecord = $stylesheet->output_string($results);
+ return ($newxmlrecord);
+}
- # set some defailts
- my $to_encoding = "UTF-8";
- my $flavour = "MARC21";
+sub marc2endnote {
+ my ($marc) = @_;
+ my $marc_rec_obj = MARC::Record->new_from_usmarc($marc);
+ my $f260 = $marc_rec_obj->field('260');
+ my $f260a = $f260->subfield('a') if $f260;
+ my $f710 = $marc_rec_obj->field('710');
+ my $f710a = $f710->subfield('a') if $f710;
+ my $f500 = $marc_rec_obj->field('500');
+ my $abstract = $f500->subfield('a') if $f500;
+ my $fields = {
+ DB => C4::Context->preference("LibraryName"),
+ Title => $marc_rec_obj->title(),
+ Author => $marc_rec_obj->author(),
+ Publisher => $f710a,
+ City => $f260a,
+ Year => $marc_rec_obj->publication_date,
+ Abstract => $abstract,
+ };
+ my $endnote;
+ my $style = new Biblio::EndnoteStyle();
+ my $template;
+ $template.= "DB - DB\n" if C4::Context->preference("LibraryName");
+ $template.="T1 - Title\n" if $marc_rec_obj->title();
+ $template.="A1 - Author\n" if $marc_rec_obj->author();
+ $template.="PB - Publisher\n" if $f710a;
+ $template.="CY - City\n" if $f260a;
+ $template.="Y1 - Year\n" if $marc_rec_obj->publication_date;
+ $template.="AB - Abstract\n" if $abstract;
+ my ($text, $errmsg) = $style->format($template, $fields);
+ return ($text);
- # first convert our ISO-2709 to MARCXML
- ($error,$marcxml) = marc2marcxml($marc,$to_encoding,$flavour);
- my $xslt_obj = XML::XSLT->new ($marcbig2marc21_slim, warnings => 1);
- $xslt_obj->transform ($marcxml);
- my $xslt_string = $xslt_obj->toString;
- $xslt_obj->dispose();
- warn $xslt_string;
- return ($error,$xslt_string);
}
+
+
=head2 html2marcxml
=over 4
$marcxml.="<leader>@$values[$i]</leader>\n";
$first=1;
# rest of the fixed fields
- } elsif (@$tags[$i] < 010) { #FIXME: <10 was the way it was, there might even be a better way
+ } elsif (@$tags[$i] lt '010') { # don't compare numerically 010 == 8
$marcxml.="<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
$first=1;
} else {
1;
__END__
-=back
-
=head1 AUTHOR
Joshua Ferraro <jmf@liblime.com>
=head1 MODIFICATIONS
-# $Id$
=cut