Bug 11650: multiplicated authorities after link_bibs_to_authorities.pl
[koha_fer] / C4 / Record.pm
index e727eb4..ed386a3 100644 (file)
@@ -28,11 +28,10 @@ use MARC::File::XML; # marc2marcxml, marcxml2marc, changeEncoding
 use MARC::Crosswalk::DublinCore; # marc2dcxml
 use Biblio::EndnoteStyle;
 use Unicode::Normalize; # _entity_encode
-use XML::LibXSLT;
-use XML::LibXML;
 use C4::Biblio; #marc2bibtex
 use C4::Csv; #marc2csv
 use C4::Koha; #marc2csv
+use C4::XSLT ();
 use YAML; #marcrecords2csv
 use Text::CSV::Encoded; #marc2csv
 
@@ -306,14 +305,7 @@ sub _transformWithStylesheet {
     # grab the XML, run it through our stylesheet, push it out to the browser
     my $xmlrecord = marc2marcxml($marc);
     my $xslfile = C4::Context->config('intrahtdocs') . $stylesheet;
-    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);
+    return C4::XSLT::engine->transform($xmlrecord, $xslfile);
 }
 
 sub marc2endnote {
@@ -461,7 +453,7 @@ sub marcrecord2csv {
     $csv->sep_char($csvseparator);
 
     # Getting the marcfields
-    my $marcfieldslist = $profile->{marcfields};
+    my $marcfieldslist = $profile->{content};
 
     # Getting the marcfields as an array
     my @marcfieldsarray = split('\|', $marcfieldslist);
@@ -668,55 +660,60 @@ sub marc2bibtex {
     }
     $author = join ' and ', @texauthors;
 
-    # Defining the conversion hash according to the marcflavour
-    my %bh;
+    # Defining the conversion array according to the marcflavour
+    my @bh;
     if ( $marcflavour eq "UNIMARC" ) {
-       
-       # FIXME, TODO : handle repeatable fields
-       # TODO : handle more types of documents
-
-       # Unimarc to bibtex hash
-       %bh = (
-
-           # Mandatory
-           author    => $author,
-           title     => $record->subfield("200", "a") || "",
-           editor    => $record->subfield("210", "g") || "",
-           publisher => $record->subfield("210", "c") || "",
-           year      => $record->subfield("210", "d") || $record->subfield("210", "h") || "",
-
-           # Optional
-           volume  =>  $record->subfield("200", "v") || "",
-           series  =>  $record->subfield("225", "a") || "",
-           address =>  $record->subfield("210", "a") || "",
-           edition =>  $record->subfield("205", "a") || "",
-           note    =>  $record->subfield("300", "a") || "",
-           url     =>  $record->subfield("856", "u") || ""
-       );
+
+        # FIXME, TODO : handle repeatable fields
+        # TODO : handle more types of documents
+
+        # Unimarc to bibtex array
+        @bh = (
+
+            # Mandatory
+            author    => $author,
+            title     => $record->subfield("200", "a") || "",
+            editor    => $record->subfield("210", "g") || "",
+            publisher => $record->subfield("210", "c") || "",
+            year      => $record->subfield("210", "d") || $record->subfield("210", "h") || "",
+
+            # Optional
+            volume  =>  $record->subfield("200", "v") || "",
+            series  =>  $record->subfield("225", "a") || "",
+            address =>  $record->subfield("210", "a") || "",
+            edition =>  $record->subfield("205", "a") || "",
+            note    =>  $record->subfield("300", "a") || "",
+            url     =>  $record->subfield("856", "u") || ""
+        );
     } else {
 
-       # Marc21 to bibtex hash
-       %bh = (
-
-           # Mandatory
-           author    => $author,
-           title     => $record->subfield("245", "a") || "",
-           editor    => $record->subfield("260", "f") || "",
-           publisher => $record->subfield("260", "b") || "",
-           year      => $record->subfield("260", "c") || $record->subfield("260", "g") || "",
-
-           # Optional
-           # unimarc to marc21 specification says not to convert 200$v to marc21
-           series  =>  $record->subfield("490", "a") || "",
-           address =>  $record->subfield("260", "a") || "",
-           edition =>  $record->subfield("250", "a") || "",
-           note    =>  $record->subfield("500", "a") || "",
-           url     =>  $record->subfield("856", "u") || ""
-       );
+        # Marc21 to bibtex array
+        @bh = (
+
+            # Mandatory
+            author    => $author,
+            title     => $record->subfield("245", "a") || "",
+            editor    => $record->subfield("260", "f") || "",
+            publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "",
+            year      => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || "",
+
+            # Optional
+            # unimarc to marc21 specification says not to convert 200$v to marc21
+            series  =>  $record->subfield("490", "a") || "",
+            address =>  $record->subfield("264", "a") || $record->subfield("260", "a") || "",
+            edition =>  $record->subfield("250", "a") || "",
+            note    =>  $record->subfield("500", "a") || "",
+            url     =>  $record->subfield("856", "u") || ""
+        );
     }
 
     $tex .= "\@book{";
-    $tex .= join(",\n", $id, map { $bh{$_} ? qq(\t$_ = {$bh{$_}}) : () } keys %bh);
+    my @elt;
+    for ( my $i = 0 ; $i < scalar( @bh ) ; $i = $i + 2 ) {
+        next unless $bh[$i+1];
+        push @elt, qq|\t$bh[$i] = {$bh[$i+1]}|;
+    }
+    $tex .= join(",\n", $id, @elt);
     $tex .= "\n}\n";
 
     return $tex;