Adding open-url lik generation to the normalization stylesheets.
authorJakub Skoczen <jakub@indexdata.dk>
Thu, 16 Aug 2007 12:40:01 +0000 (12:40 +0000)
committerJakub Skoczen <jakub@indexdata.dk>
Thu, 16 Aug 2007 12:40:01 +0000 (12:40 +0000)
etc/marc21.xsl
etc/pz2-ourl-base.xsl [new file with mode: 0644]
etc/pz2-ourl-marc21.xsl [new file with mode: 0644]

index e647c97..b8ae3ee 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- $Id: marc21.xsl,v 1.19 2007-08-16 03:12:42 quinn Exp $ -->
+<!-- $Id: marc21.xsl,v 1.20 2007-08-16 12:40:01 jakub Exp $ -->
 <xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
@@ -12,6 +12,7 @@
 <!-- Extract metadata from MARC21/USMARC 
       http://www.loc.gov/marc/bibliographic/ecbdhome.html
 -->  
+  <xsl:include href="pz2-ourl-marc21.xsl" />
   
   <xsl:template match="/marc:record">
     <xsl:variable name="title_medium" select="marc:datafield[@tag='245']/marc:subfield[@code='h']"/>
@@ -52,6 +53,7 @@
        <xsl:value-of select="$medium"/>
       </xsl:attribute>
 
+      
       <xsl:for-each select="marc:controlfield[@tag='001']">
         <pz:metadata type="id">
           <xsl:value-of select="."/>
          <xsl:value-of select="$fulltext_b"/>
        </pz:metadata>
       </xsl:if>
+
+        <pz:metadata type="open-url">
+            <xsl:call-template name="insert-md-openurl" />
+        </pz:metadata>
+
     </pz:record>
+
   </xsl:template>
 
 </xsl:stylesheet>
diff --git a/etc/pz2-ourl-base.xsl b/etc/pz2-ourl-base.xsl
new file mode 100644 (file)
index 0000000..b2e20c2
--- /dev/null
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+    version="1.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
+    xmlns:marc="http://www.loc.gov/MARC21/slim"
+    xmlns:str="http://exslt.org/strings"
+    extension-element-prefixes="str">
+
+  <xsl:variable name="resolver">http://zeus.lib.uoc.gr:3210/sfxtst3</xsl:variable>
+  <xsl:template name="insert-md-openurl">
+  
+    <xsl:value-of select="$resolver" /><xsl:text>?generatedby=pz2</xsl:text>
+    <xsl:call-template name="ou-parse-author" />
+    <xsl:call-template name="ou-parse-date" />
+    <xsl:call-template name="ou-parse-volume" />
+    <xsl:call-template name="ou-parse-any">
+      <xsl:with-param name="field_name" select="string('isbn')" />
+    </xsl:call-template>
+    <xsl:call-template name="ou-parse-any">
+      <xsl:with-param name="field_name" select="string('issn')" />
+    </xsl:call-template>
+    <xsl:call-template name="ou-parse-any">
+      <xsl:with-param name="field_name" select="string('title')" />
+    </xsl:call-template>
+    <xsl:call-template name="ou-parse-any">
+      <xsl:with-param name="field_name" select="string('atitle')" />
+    </xsl:call-template>
+
+  </xsl:template>
+  <!-- parsing raw string data -->
+  
+  <xsl:template name="ou-parse-author" >
+    <xsl:variable name="author">
+      <xsl:call-template name="ou-author" />
+    </xsl:variable>
+    
+    <xsl:variable name="aulast" select="normalize-space(substring-before($author, ','))"/>
+
+    <xsl:variable name="aufirst" 
+      select="substring-before( normalize-space(substring-after($author, ',')), ' ')"/>
+
+    <xsl:if test="$aulast != ''">
+      <xsl:text>&amp;aulast=</xsl:text>
+      <xsl:value-of select="$aulast" />
+    </xsl:if>
+
+    <xsl:if test="string-length( translate($aufirst, '.', '') ) &gt; 1" >
+      <xsl:text>&amp;aufirst=</xsl:text>
+      <xsl:value-of select="$aufirst" />
+    </xsl:if>
+
+  </xsl:template>
+
+  <xsl:template name="ou-parse-volume">
+    <xsl:variable name="volume">
+      <xsl:call-template name="ou-volume" />
+    </xsl:variable>
+
+    <xsl:variable name="vol" select="substring-after($volume, 'Vol')"/>
+    <xsl:variable name="issue" select="false()" />
+    <xsl:variable name="spage" select="false()" />
+
+    <xsl:if test="$vol">
+      <xsl:text>&amp;volume=</xsl:text>
+      <xsl:value-of select="$vol" />
+    </xsl:if>
+
+    <xsl:if test="$issue">
+      <xsl:text>&amp;issue=</xsl:text>
+      <xsl:value-of select="$issue" />
+    </xsl:if>
+    
+    <xsl:if test="$spage">
+      <xsl:text>&amp;spage=</xsl:text>
+      <xsl:value-of select="$vol" />
+    </xsl:if>
+
+  </xsl:template>
+
+
+  <xsl:template name="ou-parse-date">
+    <xsl:variable name="date">
+      <xsl:call-template name="ou-date" />
+    </xsl:variable>
+
+    <xsl:variable name="parsed_date" select="translate($date, '.[]c;', '')"/>
+
+    <xsl:if test="$parsed_date">
+      <xsl:text>&amp;date=</xsl:text>
+      <xsl:value-of select="$parsed_date" />
+    </xsl:if>
+
+  </xsl:template>
+
+  
+  <xsl:template name="ou-parse-any">
+    <xsl:param name="field_name" />
+
+    <xsl:variable name="field_value">
+      <xsl:choose>
+
+      <xsl:when test="$field_name = 'isbn'">
+        <xsl:call-template name="ou-isbn"/>
+      </xsl:when>
+
+      <xsl:when test="$field_name = 'issn'">
+        <xsl:call-template name="ou-issn"/>
+      </xsl:when>
+      
+      <xsl:when test="$field_name = 'atitle'">
+        <xsl:call-template name="ou-atitle"/>
+      </xsl:when>
+     
+      <xsl:when test="$field_name = 'title'">
+        <xsl:call-template name="ou-title"/>
+      </xsl:when>
+
+      </xsl:choose>
+    </xsl:variable>
+
+    <xsl:variable name="digits" select="1234567890"/>
+
+    <xsl:variable name="parsed_value">
+      <xsl:choose>
+
+      <xsl:when test="$field_name = 'isbn'">
+        <xsl:value-of select="translate($field_value, translate($field_value, concat($digits, 'X'), ''), '')"/>
+      </xsl:when>
+
+      <xsl:when test="$field_name = 'issn'">
+        <xsl:value-of select="translate($field_value, translate($field_value, concat($digits, '-', 'X'), ''), '')"/>
+      </xsl:when>
+      
+      <xsl:when test="$field_name = 'atitle'">
+        <xsl:value-of select="translate(normalize-space($field_value), '.', '')"/>
+      </xsl:when>
+     
+      <xsl:when test="$field_name = 'title'">
+        <xsl:value-of select="translate(normalize-space($field_value), '.', '')"/>
+      </xsl:when>
+
+      </xsl:choose>
+    </xsl:variable>
+
+
+    <xsl:if test="$parsed_value != ''">
+      <xsl:text>&amp;</xsl:text>
+      <xsl:value-of select="$field_name" />
+      <xsl:text>=</xsl:text>
+      <xsl:value-of select="$parsed_value" />
+    </xsl:if>
+
+  </xsl:template>
+
+
+</xsl:stylesheet>
+<!--
+/*
+ * Local variables:
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=2 tabstop=4 expandtab
+ */
+-->
diff --git a/etc/pz2-ourl-marc21.xsl b/etc/pz2-ourl-marc21.xsl
new file mode 100644 (file)
index 0000000..1c8efde
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+    version="1.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
+    xmlns:marc="http://www.loc.gov/MARC21/slim"
+    xmlns:str="http://exslt.org/strings"
+    extension-element-prefixes="str">  
+  
+  <xsl:import href="pz2-ourl-base.xsl"/>
+
+  <xsl:template name="ou-author" >
+  <!-- what to do with multiple authors??-->
+    <xsl:for-each select="marc:datafield[@tag='100' or @tag='700']">
+      <xsl:value-of select="marc:subfield[@code='a']"/>
+    </xsl:for-each>
+  </xsl:template>
+
+  <xsl:template name="ou-title" >
+  <!-- if 773 exists its a journal/article -->
+    <xsl:choose>
+    
+      <xsl:when test="marc:datafield[@tag='773']/marc:subfield[@code='t']">
+        <xsl:value-of select="marc:datafield[@tag='773']/marc:subfield[@code='t']"/>
+      </xsl:when>
+
+      <xsl:when test="marc:datafield[@tag='245']/marc:subfield[@code='a']">
+        <xsl:value-of select="marc:datafield[@tag='245']/marc:subfield[@code='a']"/>
+      </xsl:when>
+
+    </xsl:choose>
+  </xsl:template>
+
+  
+  <xsl:template name="ou-atitle" >
+    <!-- return value only if article or journal -->
+    <xsl:if test="marc:datafield[@tag='773']">
+      <xsl:value-of select="marc:datafield[@tag='245']/marc:subfield[@code='a']"/>
+    </xsl:if>
+  </xsl:template>
+
+
+  <xsl:template name="ou-date" >
+    <xsl:for-each select="marc:datafield[@tag='260']">
+      <xsl:value-of select="marc:subfield[@code='c']"/>
+    </xsl:for-each>
+  </xsl:template>
+
+  
+  <xsl:template name="ou-isbn" >
+  <!-- if 773 exists its a journal/article -->
+    <xsl:choose>  
+    
+      <xsl:when test="marc:datafield[@tag='773']/marc:subfield[@code='z']">
+        <xsl:value-of select="marc:datafield[@tag='773']/marc:subfield[@code='z']"/>
+      </xsl:when>
+      
+      <xsl:when test="marc:datafield[@tag='020']/marc:subfield[@code='a']">
+        <xsl:value-of select="marc:datafield[@tag='020']/marc:subfield[@code='a']"/>
+      </xsl:when>
+
+    </xsl:choose>
+  </xsl:template>
+
+  
+  <xsl:template name="ou-issn" >
+  <!-- if 773 exists its a journal/article -->
+    <xsl:choose>
+    
+      <xsl:when test="marc:datafield[@tag='773']/marc:subfield[@code='x']">
+        <xsl:value-of select="marc:datafield[@tag='773']/marc:subfield[@code='x']"/>
+      </xsl:when>
+
+      <xsl:when test="marc:datafield[@tag='022']/marc:subfield[@code='a']">
+        <xsl:value-of select="marc:datafield[@tag='022']/marc:subfield[@code='a']"/>
+      </xsl:when>
+
+      </xsl:choose>
+  </xsl:template>
+
+  
+  <xsl:template name="ou-volume" >
+    <xsl:if test="marc:datafield[@tag='773']">
+         <xsl:value-of select="marc:datafield[@tag='773']/marc:subfield[@code='g']"/>
+    </xsl:if>
+  </xsl:template>
+
+</xsl:stylesheet>
+<!--
+/*
+ * Local variables:
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=2 tabstop=4 expandtab
+ */
+-->