[Koha-devel] XSLT and superfluous "xmlns" attributes

Magnus Enger magnus at enger.priv.no
Thu Jan 17 20:58:19 CET 2013


Dear Community!

I'm having some XSLT trouble...

I have some OAI-PMH records available here:
http://sksk.bibkat.no/cgi-bin/koha/oai.pl?verb=ListRecords&metadataPrefix=marcxml

The National Library of Norway wants to harvest these records, but
they have some very specific requirements, namely that the code for
the owning library should be in 850 and that 001 should match the
record identifier used in the OAI records identifier. To achieve this,
I'm taking advantage of the OAI-PMH:ConfFile syspref, to specify an
XSLT stylesheet to transform the records on the fly. Here is the
relevant part of the ConfFile:

format:
  biblioteksok:
    metadataPrefix: biblioteksok
    metadataNamespace: http://www.loc.gov/MARC21/slim
http://www.loc.gov/standards/marcxml/schema/MARC21slim
    schema: http://www.loc.gov/MARC21/slim
http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd
    xsl_file: /home/magnus/koha/biblioteksok.xslt

and here is the stylesheet in /home/magnus/koha/biblioteksok.xslt:

<xsl:stylesheet version="1.0"
 xmlns:marc="http://www.loc.gov/MARC21/slim"
 xmlns:items="http://www.koha-community.org/items"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:package="info:srw/extension/13/package-v1.0" >

 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="marc:controlfield[@tag=001]"/>
 <xsl:template match="marc:datafield[@tag=850]"/>

 <xsl:template match="marc:leader">
  <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
<!-- Make sure the biblionumber is in the 001 field -->
   <xsl:if test="not(marc:controlfield[@tag=001])">
    <xsl:text>
  </xsl:text><xsl:element name="controlfield">
     <xsl:attribute name="tag">001</xsl:attribute>
     <xsl:value-of
select="//marc:datafield[@tag=999]/marc:subfield[@code='c']/text()"/>
    </xsl:element>
   </xsl:if>
 </xsl:template>

 <xsl:template match="marc:datafield[@tag=999]">
  <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
<!-- Put the correct string in 850a -->
  <xsl:if test="not(marc:controlfield[@tag=850])">
    <xsl:text>
    </xsl:text>
    <xsl:element name="datafield">
      <xsl:attribute name="ind1"><xsl:text> </xsl:text></xsl:attribute>
      <xsl:attribute name="ind2"><xsl:text> </xsl:text></xsl:attribute>
      <xsl:attribute name="tag">850</xsl:attribute>
      <xsl:element name="subfield">
        <xsl:attribute name="code">a</xsl:attribute>
        <xsl:text>NO-1120127</xsl:text>
      </xsl:element>
    </xsl:element>
  </xsl:if>
 </xsl:template>

</xsl:stylesheet>

And here is the result of applying the stylesheet:

http://sksk.bibkat.no/cgi-bin/koha/oai.pl?verb=ListRecords&metadataPrefix=biblioteksok

I was quite pleased with the result myself, but now the National
library is complaining that the transformed records do not validate
against http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd and
that the empty "xmlns" attribute should be removed from the following
elements:

<controlfield xmlns="" tag="001">93</controlfield>
<datafield xmlns="" ind1=" " ind2=" " tag="850">

I have no idea how to achieve that. Does anyone else have a clue?

Best regards,
Magnus Enger
libriotech.no


More information about the Koha-devel mailing list