[open-ils-commits] r13701 - in branches/rel_1_6/Open-ILS: src/perlmods/OpenILS/WWW src/perlmods/OpenILS/WWW/SuperCat xsl (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jul 22 14:11:28 EDT 2009


Author: dbs
Date: 2009-07-22 14:11:23 -0400 (Wed, 22 Jul 2009)
New Revision: 13701

Added:
   branches/rel_1_6/Open-ILS/xsl/MARC21slim2RIS.xsl
Modified:
   branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
   branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm
Log:
Patch from Warren Layton for support of RIS format in SuperCat - thanks Warren!

===

I've put together another SuperCat feed, this type for the RIS format.
This can be used with most bibliographic citation software, such as
Reference Manager and Endnote. Combined with the previous "MARC text"
feed for RefWorks, most software should be covered.

I have only included the changes to add the feed and the XSLT file.
The patch (against trunk) doesn't include any changes to the OPAC, but
I'm willing to put something together if needed.

The MARC21slim2RIS.xsl transform makes a few assumptions:
* Any authors listed in 100, 110, or 111 fields are considered
"primary authors" (A1)
* Any individuals listed in 700 fields are considered primary authors
(A1) if their last name is found in the statement of responsibility
(245c). Otherwise, they are considered secondary authors (A2). It's
not 100% accurate, but it's certainly a step up from just turning all
700-level authors into A2s.
* Corporate authors listed in 710 fields are always considered
secondary authors (A2).
* Meetings in 711 fields are always converted into "Title Series" (T3)
(i.e., a talk at a conference would have the conference name listed as
the "Title Series", with the title of the talk listed as "T1", primary
title).
* Apart from field 520 (used for Abstracts, "N2"), no 5xx fields are used
* Subfields in the 650 and 651 fields are used as keywords ("KW")

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I

    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best

    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other

    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution

    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Warren Layton 


Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm	2009-07-22 18:08:59 UTC (rev 13700)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm	2009-07-22 18:11:23 UTC (rev 13701)
@@ -797,4 +797,56 @@
 use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item';
 
 
+package OpenILS::WWW::SuperCat::Feed::ris;
+use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
+
+sub new {
+	my $class = shift;
+	my $self = $class->SUPER::new;
+	$self->{type} = 'text/plain';
+	$self->{xsl} = "/MARC21slim2RIS.xsl";
+	return $self;
+}
+
+
+our ($_parser, $_xslt, $xslt_file);
+
+sub toString {
+	my $self = shift;
+	my $base = $self->base || '';
+	my $root = $self->root || '';
+	my $search = $self->search || '';
+	my $class = $self->class || '';
+	my $lib = $self->lib || '-';
+
+	$self->composeDoc;
+
+        $_parser ||= new XML::LibXML;
+        $_xslt ||= new XML::LibXSLT;
+
+	$xslt_file ||=
+                OpenSRF::Utils::SettingsClient
+       	                ->new
+               	        ->config_value( dirs => 'xsl' ).
+                $self->{xsl};
+
+        # parse the MARC text xslt ...
+        my $ris_xslt = $_xslt->parse_stylesheet( $_parser->parse_file($xslt_file) );
+
+	my $new_doc = $ris_xslt->transform(
+		$self->{doc},
+		base_dir => "'$root'",
+		lib => "'$lib'",
+		searchTerms => "'$search'",
+		searchClass => "'$class'",
+	);
+
+	return $ris_xslt->output_string($new_doc); 
+}
+
+
+package OpenILS::WWW::SuperCat::Feed::ris::item;
+use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item';
+
+
 1;

Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm	2009-07-22 18:08:59 UTC (rev 13700)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm	2009-07-22 18:11:23 UTC (rev 13701)
@@ -145,7 +145,7 @@
 		->gather(1);
 
     $list = [ map { (keys %$_)[0] } @$list ];
-    push @$list, 'htmlholdings','html', 'marctxt';
+    push @$list, 'htmlholdings','html', 'marctxt', 'ris';
 
     for my $browse_axis ( qw/title author subject topic series item-age/ ) {
         for my $record_browse_format ( @$list ) {
@@ -260,6 +260,7 @@
 	<format name='html-full' type='text/html'/>
 	<format name='htmlholdings-full' type='text/html'/>
 	<format name='marctxt' type='text/plain'/>
+	<format name='ris' type='text/plain'/>
 				FORMATS
 			} elsif ($type eq 'metarecord') {
 				$body .= <<"				FORMATS";
@@ -315,6 +316,7 @@
 	<format name='html-full' type='text/html'/>
 	<format name='htmlholdings-full' type='text/html'/>
 	<format name='marctxt' type='text/plain'/>
+	<format name='ris' type='text/plain'/>
 			FORMATS
 
 
@@ -407,7 +409,7 @@
 	       @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
 	     and !grep
 	       { $_ eq $base_format }
-	       qw/opac html htmlholdings marctxt/
+	       qw/opac html htmlholdings marctxt ris/
 	) {
 		print "Content-type: text/html; charset=utf-8\n\n";
 		$apache->custom_response( 406, <<"		HTML");
@@ -553,6 +555,10 @@
 				   <format>
 				     <name>marctxt</name>
 				     <type>text/plain</type>
+				   </format>
+				   <format>
+				     <name>ris</name>
+				     <type>text/plain</type>
 				   </format>";
 			}
 
@@ -622,6 +628,10 @@
 			   <format>
 			     <name>marctxt</name>
 			     <type>text/plain</type>
+			   </format>
+			   <format>
+			     <name>ris</name>
+			     <type>text/plain</type>
 			   </format>";
 
 		for my $h (@$list) {
@@ -1232,7 +1242,7 @@
 	$feed->unapi($unapi) if ($flesh);
 
 	$type = 'atom' if ($type eq 'html');
-	$type = 'marcxml' if (($type eq 'htmlholdings') || ($type eq 'marctxt'));
+	$type = 'marcxml' if (($type eq 'htmlholdings') || ($type eq 'marctxt') || ($type eq 'ris'));
 
 	#$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
 

Copied: branches/rel_1_6/Open-ILS/xsl/MARC21slim2RIS.xsl (from rev 13700, trunk/Open-ILS/xsl/MARC21slim2RIS.xsl)
===================================================================
--- branches/rel_1_6/Open-ILS/xsl/MARC21slim2RIS.xsl	                        (rev 0)
+++ branches/rel_1_6/Open-ILS/xsl/MARC21slim2RIS.xsl	2009-07-22 18:11:23 UTC (rev 13701)
@@ -0,0 +1,284 @@
+<?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" exclude-result-prefixes="marc">
+    <xsl:include href="MARC21slimUtils.xsl"/>
+    <xsl:output method="text"/>
+
+    <xsl:template match="marc:record">
+        <xsl:variable name="leader" select="marc:leader" />
+        <xsl:variable name="leader6" select="substring($leader,7,1)" />
+        <xsl:variable name="leader7" select="substring($leader,8,1)" />
+
+        <xsl:text>&#10;TY  - </xsl:text>
+
+        <xsl:variable name="field008" select="marc:controlfield[@tag=008]"/>
+
+        <xsl:choose>
+            <xsl:when test="$leader6='a' or $leader6='t'">
+                <xsl:choose>
+                    <xsl:when test="$leader6='a' and $leader7='b' or $leader7='i' or $leader7='s'">
+                        <!-- Continuing Resource -->
+                        <xsl:variable name="field008-21" select="substring($field008,22,1)"/>
+                        <xsl:choose>
+                            <xsl:when test="$field008-21='p'">JOUR</xsl:when>
+                            <xsl:when test="$field008-21='n'">NEWS</xsl:when>
+                            <xsl:when test="$field008-21='m'">SER</xsl:when>
+
+                            <!-- Default to Journal -->
+                            <xsl:otherwise>JOUR</xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <!-- If not a CR, then a book (or book-type) item -->
+                        <xsl:variable name="field008-24-27" select="substring($field008,25,4)"/>
+                        <xsl:variable name="field008-29" select="substring($field008,30,1)"/>
+
+                        <xsl:choose>
+                            <xsl:when test="$leader6='a' and $leader7='m'">BOOK</xsl:when> 
+                            <xsl:when test="$leader6='a' and $leader7='a'">CHAP</xsl:when> 
+                            <xsl:when test="$field008-29='1'">CONF</xsl:when> 
+                            <xsl:when test="$field008-24-27='m'">THES</xsl:when> 
+                            <xsl:when test="$field008-24-27='a'">ABST</xsl:when> 
+                            <xsl:when test="$field008-24-27='j'">PAT</xsl:when> 
+                            <xsl:when test="$field008-24-27='v'">CASE</xsl:when> 
+                            <xsl:when test="$field008-24-27='l'">STAT</xsl:when> 
+                            <xsl:when test="$field008-24-27='t'">RPRT</xsl:when> 
+                            <xsl:when test="$field008-24-27='c'">CTLG</xsl:when> 
+
+                            <!-- Default to BOOK -->
+                            <xsl:otherwise>BOOK</xsl:otherwise>
+                        </xsl:choose>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:when>
+
+            <xsl:when test="$leader6='e' or $leader6='f'">MAP</xsl:when>
+            <xsl:when test="$leader6='i' or $leader6='j'">SOUND</xsl:when>
+            <xsl:when test="$leader6='c' or $leader6='d'">MUSIC</xsl:when>
+
+            <xsl:when test="$leader6='g'">
+                <xsl:variable name="field008-33" select="substring($field008,34,1)"/>
+                <xsl:choose>
+                    <xsl:when test="$field008-33='m' or $field008-33='f'">MPCT</xsl:when>
+                    <xsl:when test="$field008-33='v'">VIDEO</xsl:when>
+                    <xsl:when test="$field008-33='s'">SLIDE</xsl:when>
+
+                    <!-- Default to Motion Picture -->
+                    <xsl:otherwise>MPCT</xsl:otherwise>
+                </xsl:choose>
+            </xsl:when>
+            <xsl:when test="$leader6='k' or $leader6='r'">
+                <xsl:variable name="field008-33" select="substring($field008,34,1)"/>
+                <xsl:choose>
+                    <xsl:when test="$field008-33='a' or $field008-33='c' or $field008-33='i' or $field008-33='k'">ART</xsl:when>
+
+                    <!-- Default to Generic -->
+                    <xsl:otherwise>GEN</xsl:otherwise>
+                </xsl:choose>
+            </xsl:when>
+
+            <xsl:when test="$leader6='m'">
+                <xsl:variable name="field008-26" select="substring($field008,27,1)"/>
+                <xsl:choose>
+                    <xsl:when test="$field008-26='b'">COMP</xsl:when>
+                    <xsl:when test="$field008-26='e'">ELEC</xsl:when>
+                    <xsl:when test="$field008-26='a' or $field008-26='c' or $field008-26='d'">DATA</xsl:when>
+
+                    <!-- Default to Computer File -->
+                    <xsl:otherwise>COMP</xsl:otherwise>
+                </xsl:choose>
+            </xsl:when>
+
+            <xsl:otherwise>GEN</xsl:otherwise>
+
+        </xsl:choose> <!-- End TY -->
+
+
+        <xsl:for-each select="marc:datafield[@tag=100]|marc:datafield[@tag=110]|marc:datafield[@tag=111]">
+            <xsl:text>&#10;A1  - </xsl:text>
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="punctuation">
+                        <xsl:text>,; </xsl:text>
+                    </xsl:with-param>
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:for-each>
+            <xsl:if test="@tag = '110'">
+                <xsl:for-each select="marc:subfield[@code='b']">
+                    <xsl:value-of select="."/>
+                </xsl:for-each>
+            </xsl:if>
+            <xsl:if test="@tag = '111'">
+                <xsl:for-each select="marc:subfield[@code='q']">
+                    <xsl:value-of select="."/>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='e']">
+                    <xsl:value-of select="."/>
+                </xsl:for-each>
+            </xsl:if>
+        </xsl:for-each>
+        
+        <xsl:for-each select="marc:datafield[@tag=245]">
+            <xsl:text>&#10;T1  - </xsl:text>
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="punctuation">
+                        <xsl:text>:/ </xsl:text>
+                    </xsl:with-param>
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:for-each>
+            <xsl:for-each select="marc:subfield[@code='b']">
+                <xsl:text>: </xsl:text>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="punctuation">
+                        <xsl:text>/ </xsl:text>
+                    </xsl:with-param>
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:variable name="respStmt" select="marc:datafield[@tag=245]/marc:subfield[@code='c']"/>
+
+        <xsl:for-each select="marc:datafield[@tag=700]">
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:variable name="addedAuthor" select="."/>
+                <xsl:choose>
+                    <xsl:when test="contains($respStmt, substring-before($addedAuthor, ', '))">
+                        <xsl:text>&#10;A1  - </xsl:text>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="punctuation">
+                                <xsl:text>,; </xsl:text>
+                            </xsl:with-param>
+                            <xsl:with-param name="chopString">
+                                <xsl:value-of select="$addedAuthor"/>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:text>&#10;A2  - </xsl:text>
+                        <xsl:call-template name="chopPunctuation">
+                            <xsl:with-param name="punctuation">
+                                <xsl:text>,; </xsl:text>
+                            </xsl:with-param>
+                            <xsl:with-param name="chopString">
+                                <xsl:value-of select="$addedAuthor"/>
+                            </xsl:with-param>
+                        </xsl:call-template>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=710]">
+            <xsl:text>&#10;A2  - </xsl:text>
+            <xsl:for-each select="marc:subfield[@code='a']|marc:subfield[@code='b']">
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=490]|marc:datafield[@tag=711]">
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:text>&#10;T3  - </xsl:text>
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+            <xsl:if test="@tag = '711'">
+                <xsl:for-each select="marc:subfield[@code='q']">
+                    <xsl:value-of select="."/>
+                </xsl:for-each>
+                <xsl:for-each select="marc:subfield[@code='e']">
+                    <xsl:value-of select="."/>
+                </xsl:for-each>
+            </xsl:if>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=210]">
+            <xsl:text>&#10;JO  - </xsl:text>
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=222]">
+            <xsl:text>&#10;JF  - </xsl:text>
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=260]">
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:text>&#10;CY  - </xsl:text>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="punctuation">
+                        <xsl:text> :</xsl:text>
+                    </xsl:with-param>
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:for-each>
+            <xsl:for-each select="marc:subfield[@code='b']">
+                <xsl:text>&#10;PB  - </xsl:text>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="punctuation">
+                        <xsl:text> ,</xsl:text>
+                    </xsl:with-param>
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+            </xsl:for-each>
+            <xsl:for-each select="marc:subfield[@code='c']">
+                <xsl:text>&#10;PY  - </xsl:text>
+                <xsl:call-template name="chopPunctuation">
+                    <xsl:with-param name="punctuation">
+                        <xsl:text> .</xsl:text>
+                    </xsl:with-param>
+                    <xsl:with-param name="chopString">
+                        <xsl:value-of select="."/>
+                    </xsl:with-param>
+                </xsl:call-template>
+                <xsl:text>///</xsl:text>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=520]">
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:text>&#10;N2  - </xsl:text>
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=650]|marc:datafield[@tag=651]">
+            <xsl:for-each select="marc:subfield">
+                <xsl:text>&#10;KW  - </xsl:text>
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=856]">
+            <xsl:for-each select="marc:subfield[@code='u']">
+                <xsl:text>&#10;UR  - </xsl:text>
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:for-each select="marc:datafield[@tag=020]|marc:datafield[@tag=022]">
+            <xsl:text>&#10;SN  - </xsl:text>
+            <xsl:for-each select="marc:subfield[@code='a']">
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </xsl:for-each>
+
+        <xsl:text>&#10;ER  -&#10;</xsl:text>
+	</xsl:template>
+</xsl:stylesheet>
+



More information about the open-ils-commits mailing list