From: miker Date: Sat, 3 Feb 2007 15:58:11 +0000 (+0000) Subject: utility for turning MARC into HTML for easy viewing X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=600f91c8f508a0fad81971c554a7de640a9cce9e;p=Evergreen.git utility for turning MARC into HTML for easy viewing git-svn-id: svn://svn.open-ils.org/ILS/trunk@6859 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/extras/marc2html b/Open-ILS/src/extras/marc2html new file mode 100755 index 0000000000..c076e4c396 --- /dev/null +++ b/Open-ILS/src/extras/marc2html @@ -0,0 +1,218 @@ +#!/usr/bin/perl + +use Error; +use MARC::Batch; +use MARC::File::XML; +use XML::LibXSLT; +use XML::LibXML; +use Unicode::Normalize; +use Getopt::Long; + +my ($split,$enc,$marc,$out) = (100); +GetOptions( + 'split=i' => \$split, + 'marc=s' => \$marc, + 'encoding=s' => \$enc, + 'out_dir=s' => \$out, +); + +if ($enc) { + MARC::Charset->ignore_errors(1); + MARC::Charset->assume_encoding($enc); +} + +die "gimme some marc!\n" unless $marc; +die "gimme somewhere to put it!\n" unless $out; + +my $xsl = join('',()); + +my $parser = XML::LibXML->new(); +my $xslt = XML::LibXSLT->new(); + +$stylesheet = $xslt->parse_stylesheet( $parser->parse_string($xsl) ); + + +my $xml = ''; +my $current = 1; +my $prev = 0; +my $next = 2; + +my $marc = MARC::Batch->new( USMARC => $marc ); +$marc->strict_off; +$marc->warnings_off; + +while (my $r = $marc->next) { + $xml .= entityize(MARC::File::XML::record($r)); + + unless ($current % $split) { + $xml = <<" XML"; + + $xml + + XML + + my $doc = $parser->parse_string($xml); + $xml = ''; + + my $results = $stylesheet->transform($doc, prev => "'$prev'", next => "'$next'"); + $prev++; + $next++; + + open OUT, ">$out/$prev.html"; + print OUT $results->toString; + close OUT; + } + $current++; +} + +my $doc = $parser->parse_string(< + $xml + +XML + +my $results = $stylesheet->transform($doc, prev => "'$prev'", next => "'0'"); +$prev++; + +$stylesheet->output_file($results, "$out/$prev.html"); + + +sub entityize { + my $stuff = shift; + my $form = shift; + + if ($form eq 'D') { + $stuff = NFD($stuff); + } else { + $stuff = NFC($stuff); + } + + $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; + $stuff =~ s/([\x00-\x19])//sgoe; + return $stuff; +} + + + +__DATA__ + + + + + + + + + + + + + + + + + + + Previous page + + + | + + + + + + Next page + + +
+ + + + + + + Previous page + + + | + + + + + + Next page + + + + +
+ + + + + + + + +
+ LDR + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + + + + + ‡ + + + +
+