1 <?xml version="1.0" encoding="UTF-8"?>
3 Converts MarcXML to TurboMarc
4 (to benefit from pazpar2's improved tmarc.xsl)
6 Also includes a provision to handle PicaMarc where datafield names can
7 contain a @ that is changed to Ä to give valid XML.
10 Sven-S. Porst, SUB Göttingen <porst@sub.uni-goettingen.de>
14 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
15 xmlns:tmarc="http://www.indexdata.com/turbomarc"
16 xmlns:marc="http://www.loc.gov/MARC21/slim">
18 <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
20 <xsl:template match="@*|node()">
22 <xsl:apply-templates select="@*|node()"/>
27 <xsl:template match="record|marc:record">
28 <xsl:element name="r" namespace="http://www.indexdata.com/turbomarc">
29 <xsl:apply-templates select="@*|node()"/>
34 <xsl:template match="leader|marc:leader">
35 <xsl:element name="l" namespace="http://www.indexdata.com/turbomarc">
36 <xsl:apply-templates select="@*|node()"/>
41 <xsl:template match="controlfield|datafield|subfield|marc:controlfield|marc:datafield|marc:subfield">
43 Try to mock Indexdata's specification without regexps:
44 Translate all allowed characters to 'a' and assume field names are
45 shorter than 62 characters.
46 Given the typical 3 digit Marc field numbers this seems
47 safe in the practical cases I have seen.
49 http://www.indexdata.com/blog/2010/05/turbomarc-faster-xml-marc-records
50 http://www.indexdata.com/yaz/doc/marc.html
53 <xsl:variable name="allowedCharacters" select="'0123465789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@'"/>
54 <xsl:variable name="manyAs" select="'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'"/>
57 <xsl:when test="(name(.)='datafield' or name(.)='controlfield') and
58 contains($manyAs, translate(@tag, $allowedCharacters, $manyAs))">
59 <xsl:element name="{concat(substring(local-name(),1,1), translate(@tag,'@','Ä'))}"
60 namespace="http://www.indexdata.com/turbomarc">
61 <xsl:apply-templates select="@*[name(.)!='tag']|node()"/>
65 <xsl:when test="name(.)='subfield' and
66 contains($manyAs, translate(@code, $allowedCharacters, $manyAs))">
67 <xsl:element name="{concat(substring(local-name(),1,1), @code)}"
68 namespace="http://www.indexdata.com/turbomarc">
69 <xsl:apply-templates select="@*[name(.)!='code']|node()"/>
75 <xsl:apply-templates select="@*|node()"/>