[Koha-cvs] koha/C4 Record.pm [rel_3_0]

Joshua Ferraro jmf at liblime.com
Tue Feb 20 06:35:26 CET 2007


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Joshua Ferraro <kados>	07/02/20 05:35:26

Modified files:
	C4             : Record.pm 

Log message:
	updates to Record.pm, now includes support for DC and MODS

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Record.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.2&r2=1.4.2.3

Patches:
Index: Record.pm
===================================================================
RCS file: /sources/koha/koha/C4/Attic/Record.pm,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -u -b -r1.4.2.2 -r1.4.2.3
--- Record.pm	18 Dec 2006 17:44:06 -0000	1.4.2.2
+++ Record.pm	20 Feb 2007 05:35:26 -0000	1.4.2.3
@@ -18,21 +18,22 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 #
-# $Id: Record.pm,v 1.4.2.2 2006/12/18 17:44:06 toins Exp $
+# $Id: Record.pm,v 1.4.2.3 2007/02/20 05:35:26 kados Exp $
 #
-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 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: 1.4.2.2 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.4.2.3 $' =~ /\d+/g;
                 shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 @ISA = qw(Exporter);
@@ -247,7 +248,19 @@
         $crosswalk = MARC::Crosswalk::DublinCore->new( qualified => 1 );
     }
     my $dcxml = $crosswalk->as_dublincore($marc_record_obj);
-    return ($error,$dcxml);
+	my $dcxmlfinal = "<?xml version=\"1.0\"?>\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
 
@@ -262,31 +275,18 @@
 =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;
-    }
-
-    # set some defailts
-    my $to_encoding = "UTF-8";
-    my $flavour = "MARC21";
-    
-    # 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);
+	# grab the XML, run it through our stylesheet, push it out to the browser
+	my $xmlrecord = marc2marcxml($marc);
+	my $xslfile = C4::Context->config('intranetdir')."/misc/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);
 }
 =head2 html2marcxml
 
@@ -459,6 +459,8 @@
     }
     #}
     # the last has not been included inside the loop... do it now !
+    #use Data::Dumper;
+    #warn Dumper($field->{_subfields});
     $record->add_fields($field) if (($field) && $field ne "");
     #warn "HTML2MARC=".$record->as_formatted;
     return $record;
@@ -560,14 +562,12 @@
 1;
 __END__
 
-=back
-
 =head1 AUTHOR
 
 Joshua Ferraro <jmf at liblime.com>
 
 =head1 MODIFICATIONS
 
-# $Id: Record.pm,v 1.4.2.2 2006/12/18 17:44:06 toins Exp $
+# $Id: Record.pm,v 1.4.2.3 2007/02/20 05:35:26 kados Exp $
 
 =cut





More information about the Koha-cvs mailing list