--- /dev/null
+#!/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('',(<DATA>));
+
+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";
+ <collection xmlns="http://www.loc.gov/MARC21/slim">
+ $xml
+ </collection>
+ 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);
+<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">
+ $xml
+</marc:collection>
+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__
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="html"/>
+
+ <xsl:template match="/">
+ <html>
+ <head>
+
+ <style>
+
+ .marc_table {}
+ .marc_tag_row {}
+ .marc_tag_data {}
+ .marc_tag_col {}
+ .marc_tag_ind {}
+ .marc_subfields {}
+ .marc_subfield_code {
+ color: blue;
+ padding-left: 5px;
+ padding-right: 5px;
+ }
+
+ </style>
+
+ <link href='/css/opac_marc.css' rel='stylesheet' type='text/css'></link>
+ </head>
+ <body>
+ <xsl:if test="$prev > 0">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat( $prev, '.html')"/>
+ </xsl:attribute>
+ <xsl:text>Previous page</xsl:text>
+ </a>
+ </xsl:if>
+ <span> | </span>
+ <xsl:if test="$next > 0">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat( $next, '.html')"/>
+ </xsl:attribute>
+ <xsl:text>Next page</xsl:text>
+ </a>
+ </xsl:if>
+ <hr/>
+ <xsl:apply-templates select="//marc:record"/>
+ <xsl:if test="$prev > 0">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat( $prev, '.html')"/>
+ </xsl:attribute>
+ <xsl:text>Previous page</xsl:text>
+ </a>
+ </xsl:if>
+ <span> | </span>
+ <xsl:if test="$next > 0">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat( $next, '.html')"/>
+ </xsl:attribute>
+ <xsl:text>Next page</xsl:text>
+ </a>
+ </xsl:if>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="marc:record">
+ <table class='marc_table'>
+ <tr class='marc_tag_row'>
+ <th class='marc_tag_col' NOWRAP="TRUE" ALIGN="RIGHT" VALIGN="middle">
+ LDR
+ </th>
+ <td class='marc_tag_data' COLSPAN='3'>
+ <xsl:value-of select="marc:leader"/>
+ </td>
+ </tr>
+ <xsl:apply-templates select="marc:datafield|marc:controlfield"/>
+ </table>
+ <hr/>
+ </xsl:template>
+
+ <xsl:template match="marc:controlfield">
+ <tr class='marc_tag_row'>
+ <th class='marc_tag_col' NOWRAP="TRUE" ALIGN="RIGHT" VALIGN="middle">
+ <xsl:value-of select="@tag"/>
+ </th>
+ <td class='marc_tag_data' COLSPAN='3'>
+ <xsl:value-of select="."/>
+ </td>
+ </tr>
+ </xsl:template>
+
+ <xsl:template match="marc:datafield">
+ <tr class='marc_tag_row'>
+ <th class='marc_tag_col' NOWRAP="TRUE" ALIGN="RIGHT" VALIGN="middle">
+ <xsl:value-of select="@tag"/>
+ </th>
+ <td class='marc_tag_ind'>
+ <xsl:value-of select="@ind1"/>
+ </td>
+
+ <td class='marc_tag_ind' style='border-left: 1px solid #A0A0A0; padding-left: 3px;'>
+ <xsl:value-of select="@ind2"/>
+ <span style='color:#FFF'>.</span>
+ </td>
+
+ <td class='marc_subfields'>
+ <xsl:apply-templates select="marc:subfield"/>
+ </td>
+ </tr>
+ </xsl:template>
+
+ <xsl:template match="marc:subfield">
+ <span class='marc_subfield_code' >
+ ‡<xsl:value-of select="@code"/>
+ </span><xsl:value-of select="."/>
+ </xsl:template>
+
+</xsl:stylesheet>
+