-
-
Save l2c2technologies/f5ea4e0a6b1647fe5f9c68c95316c28a to your computer and use it in GitHub Desktop.
XSLT transformation to make Koha's OAI-PMH records comply with the harvesting for Biblioteksøk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 method="xml" omit-xml-declaration="yes" indent="yes"/> | |
<xsl:template match="node()|@*"> | |
<xsl:copy> | |
<xsl:apply-templates select="node()|@*"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- Remove the original versions of these fields --> | |
<xsl:template match="marc:controlfield[@tag=001]"/> | |
<xsl:template match="marc:datafield[@tag=850]"/> | |
<!-- Add a new 001 that contains the biblionumber from 999$c --> | |
<xsl:template match="marc:leader"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
<xsl:if test="not(marc:controlfield[@tag=001])"> | |
<xsl:text> | |
</xsl:text><xsl:element name="controlfield" xmlns="http://www.loc.gov/MARC21/slim"> | |
<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> | |
<!-- Add a new 850$a that contains a hardcoded string --> | |
<xsl:template match="marc:datafield[@tag=999]"> | |
<!-- xsl:template match="marc:record" --> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
<xsl:if test="not(marc:controlfield[@tag=850])"> | |
<xsl:text> | |
</xsl:text> | |
<xsl:element name="datafield" xmlns="http://www.loc.gov/MARC21/slim"> | |
<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:text> | |
</xsl:text> | |
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<record | |
xmlns='http://www.loc.gov/MARC21/slim' | |
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' | |
xsi:schemaLocation='http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd'> | |
<leader>00581nam a2200205 a 4500</leader> | |
<controlfield tag="001">999</controlfield> | |
<controlfield tag='008'> r eng </controlfield> | |
<datafield ind1=' ' ind2=' ' tag='100'> | |
<subfield code='a'>Author 2</subfield> | |
</datafield> | |
<datafield ind1=' ' ind2=' ' tag='245'> | |
<subfield code='a'>Title 2</subfield> | |
</datafield> | |
<datafield ind1=' ' ind2=' ' tag='999'> | |
<subfield code='c'>2</subfield> | |
<subfield code='d'>2</subfield> | |
</datafield> | |
</record> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use XML::LibXML; | |
use XML::LibXSLT; | |
use Modern::Perl; | |
my $xsl='biblioteksok.xslt'; | |
my $xml='record.marcxml'; | |
my $xslt = XML::LibXSLT->new(); | |
my $source = XML::LibXML->load_xml(location => $xml); | |
my $style_doc = XML::LibXML->load_xml(location=>$xsl, no_cdata=>1); | |
my $stylesheet = $xslt->parse_stylesheet($style_doc); | |
my $results = $stylesheet->transform($source); | |
print $stylesheet->output_as_bytes($results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment