Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/pazpar2
authorDennis Schafroth <dennis@indexdata.com>
Wed, 29 Feb 2012 11:20:45 +0000 (12:20 +0100)
committerDennis Schafroth <dennis@indexdata.com>
Wed, 29 Feb 2012 11:20:45 +0000 (12:20 +0100)
etc/MarcXML2TurboMarc.xsl [new file with mode: 0644]
etc/marc21.xsl
etc/tmarc.xsl

diff --git a/etc/MarcXML2TurboMarc.xsl b/etc/MarcXML2TurboMarc.xsl
new file mode 100644 (file)
index 0000000..566fe03
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Converts MarcXML to TurboMarc
+    (to benefit from pazpar2's improved tmarc.xsl)
+
+    Also includes a provision to handle PicaMarc where datafield names can
+    contain a @ that is changed to Ä to give valid XML.
+    2010-2011
+    Sven-S. Porst, SUB Göttingen <porst@sub.uni-goettingen.de>
+-->
+<xsl:stylesheet
+   version="1.0"
+   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+   xmlns:tmarc="http://www.indexdata.com/turbomarc"
+   xmlns:marc="http://www.loc.gov/MARC21/slim">
+
+<xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
+
+<xsl:template match="@*|node()">
+  <xsl:copy>
+    <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+</xsl:template>
+
+
+<xsl:template match="record|marc:record">
+  <xsl:element name="r" namespace="http://www.indexdata.com/turbomarc">
+    <xsl:apply-templates select="@*|node()"/>
+    </xsl:element>
+</xsl:template>
+
+
+<xsl:template match="leader|marc:leader">
+  <xsl:element name="l" namespace="http://www.indexdata.com/turbomarc">
+    <xsl:apply-templates select="@*|node()"/>
+    </xsl:element>
+</xsl:template>
+
+
+<xsl:template match="controlfield|datafield|subfield|marc:controlfield|marc:datafield|marc:subfield">
+  <!--
+      Try to mock Indexdata's specification without regexps:
+      Translate all allowed characters to 'a' and assume field names are
+      shorter than 62 characters.
+      Given the typical 3 digit Marc field numbers this seems
+      safe in the practical cases I have seen.
+
+      http://www.indexdata.com/blog/2010/05/turbomarc-faster-xml-marc-records
+      http://www.indexdata.com/yaz/doc/marc.html
+      -->
+
+  <xsl:variable name="allowedCharacters" select="'0123465789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@'"/>
+  <xsl:variable name="manyAs" select="'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'"/>
+
+  <xsl:choose>
+    <xsl:when test="(name(.)='datafield' or name(.)='controlfield') and
+                   contains($manyAs, translate(@tag, $allowedCharacters, $manyAs))">
+      <xsl:element name="{concat(substring(local-name(),1,1), translate(@tag,'@','Ä'))}"
+                  namespace="http://www.indexdata.com/turbomarc">
+       <xsl:apply-templates select="@*[name(.)!='tag']|node()"/>
+       </xsl:element>
+      </xsl:when>
+
+    <xsl:when test="name(.)='subfield' and
+                   contains($manyAs, translate(@code, $allowedCharacters, $manyAs))">
+      <xsl:element name="{concat(substring(local-name(),1,1), @code)}"
+                  namespace="http://www.indexdata.com/turbomarc">
+       <xsl:apply-templates select="@*[name(.)!='code']|node()"/>
+       </xsl:element>
+      </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:copy>
+       <xsl:apply-templates select="@*|node()"/>
+       </xsl:copy>
+      </xsl:otherwise>
+    </xsl:choose>
+</xsl:template>
+
+
+</xsl:stylesheet>
index dacf75a..e7bee0c 100644 (file)
                                </xsl:variable>
                                <xsl:choose>
                                        <xsl:when test="substring($value,string-length($value)) = ','">
-                                               <xsl:value-of select="substring($value,0,string-length($value))" />
+                                               <xsl:value-of select="substring($value,1,string-length($value)-1)" />
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:value-of select="$value" />
          <xsl:value-of select="marc:subfield[@code='u']"/>
        </pz:metadata>
        <pz:metadata type="electronic-text">
-         <xsl:value-of select="marc:subfield[@code='y' or @code='3']"/>
+         <xsl:value-of select="marc:subfield[@code='y' or @code='3' or @code='a']"/>
        </pz:metadata>
        <pz:metadata type="electronic-note">
          <xsl:value-of select="marc:subfield[@code='z']"/>
index 0cdaebf..faaa3ab 100644 (file)
         </pz:metadata>
       </xsl:for-each>
 
-       <xsl:for-each select="tmarc:d600">
-               <pz:metadata type="subject">
-                       <xsl:value-of select="tmarc:sa" />
-               </pz:metadata>
-               <pz:metadata type="subject-long">
-                       <xsl:for-each select="node()/text()">
-                               <xsl:if test="position() > 1">
-                                       <xsl:text>, </xsl:text>
-                               </xsl:if>
-                               <xsl:variable name='value'>
-                                       <xsl:value-of select='normalize-space(.)' />
-                               </xsl:variable>
-                               <xsl:choose>
-                                       <xsl:when test="substring($value,string-length($value)) = ','">
-                                               <xsl:value-of select="substring($value,0,string-length($value))" />
-                                       </xsl:when>
-                                       <xsl:otherwise>
-                                               <xsl:value-of select="$value" />
-                                       </xsl:otherwise>
-                               </xsl:choose>
-                       </xsl:for-each>
-               </pz:metadata>
-       </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d610">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d611">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d630">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d648">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d650">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d651">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d653">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d654">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
+      <xsl:for-each select="tmarc:d600 | tmarc:d610 | tmarc:d611 | tmarc:d630 |
+                            tmarc:d648 | tmarc:d650 | tmarc:d651 | tmarc:d653 |
+                            tmarc:d654 | tmarc:d655 | tmarc:d656 | tmarc:d657 |
+                            tmarc:d658 | tmarc:d662 | tmarc:d69X">
+         <pz:metadata type="subject">
+           <xsl:value-of select="tmarc:sa"/>
+         </pz:metadata>
+         <pz:metadata type="subject-long">
+           <xsl:for-each select="node()/text()">
+             <xsl:if test="position() &gt; 1">
+               <xsl:text>, </xsl:text>
+             </xsl:if>
+            <xsl:variable name='value'>
+              <xsl:value-of select='normalize-space(.)'/>
+            </xsl:variable>
+            <xsl:choose>
+              <xsl:when test="substring($value, string-length($value)) = ','">
+                <xsl:value-of select="substring($value, 1, string-length($value)-1)"/>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:value-of select="$value"/>
+              </xsl:otherwise>
+            </xsl:choose> 
           </xsl:for-each>
-        </pz:metadata>
+         </pz:metadata>
       </xsl:for-each>
 
-      <xsl:for-each select="tmarc:d655">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-            <xsl:value-of select="." />
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d656">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d657">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-            <xsl:value-of select="." />
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d658">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d662">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <xsl:for-each select="tmarc:d69X">
-        <pz:metadata type="subject">
-          <xsl:value-of select="tmarc:sa" />
-        </pz:metadata>
-        <pz:metadata type="subject-long">
-          <xsl:for-each select="node()/text()">
-            <xsl:if test="position() > 1">
-              <xsl:text>, </xsl:text>
-            </xsl:if>
-                <xsl:variable name='value'>
-                    <xsl:value-of select='normalize-space(.)' />
-                </xsl:variable>
-                <xsl:choose>
-                    <xsl:when test="substring($value,string-length($value)) = ','">
-                        <xsl:value-of select="substring($value,0,string-length($value))" />
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select="$value" />
-                    </xsl:otherwise>
-                </xsl:choose>
-          </xsl:for-each>
-        </pz:metadata>
-      </xsl:for-each>
-
-      <!-- or tmarc:d651 or tmarc:d653 or tmarc:d654 or tmarc:d655 or tmarc:d656 
-        or tmarc:d657 or tmarc:d658 or tmarc:d662 or tmarc:d69X"> -->
-
-      <!-- <xsl:for-each select="tmarc:d600" > <pz:metadata type="subject"> 
-        <xsl:value-of select="tmarc:sa"/> </pz:metadata> <pz:metadata type="subject-long"> 
-        <xsl:for-each select="tmarc:sa tmarc:sb tmarc:sc tmarc:sd "> <xsl:if test="position() 
-        > 1"> <xsl:text>, </xsl:text> </xsl:if> <xsl:value-of select="."/> </xsl:for-each> 
-        </pz:metadata> </xsl:for-each> -->
-
       <xsl:for-each select="tmarc:d856">
         <pz:metadata type="electronic-url">
           <xsl:value-of select="tmarc:su" />
              <xsl:when test="tmarc:s3">
                   <xsl:value-of select="tmarc:s3/text()" />
              </xsl:when>
+             <xsl:when test="tmarc:sa">
+                  <xsl:value-of select="tmarc:sa/text()" />
+             </xsl:when>
              <xsl:otherwise>Get resource</xsl:otherwise>
             </xsl:choose>
         </pz:metadata>