Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XSLT to convert OAI XML with DIM metadata to Crossref submission XML for DOI registration
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: Converts metadata from DSpace Intermediat Format (DIM) into
metadata following the Crossref Schema version 4.3.6.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:oai="http://www.openarchives.org/OAI/2.0/"
xmlns:dspace="http://www.dspace.org/xmlns/dspace/dim"
xmlns:uuid="java:java.util.UUID"
xmlns:date="java:java.lang.System"
xmlns="http://www.crossref.org/schema/4.3.6"
version="2.0">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<!-- Don't copy everything by default! -->
<xsl:template match="@* | text()" />
<xsl:template match="//oai:ListRecords">
<doi_batch version="4.3.6" xmlns="http://www.crossref.org/schema/4.3.6"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.crossref.org/schema/4.3.6 http://www.crossref.org/schemas/crossref4.3.6.xsd">
<head>
<doi_batch_id><xsl:value-of select="uuid:randomUUID()"/></doi_batch_id>
<timestamp><xsl:value-of select="date:currentTimeMillis()"/></timestamp>
<depositor>
<depositor_name>UdL</depositor_name>
<email_address>alexandre.magaz@udl.cat</email_address>
</depositor>
<registrant>CrossRef</registrant>
</head>
<body>
<journal>
<journal_metadata>
<full_title>Imago temporis: medium Aevum</full_title>
<issn>1888-3931</issn>
</journal_metadata>
<xsl:apply-templates />
</journal>
</body>
</doi_batch>
</xsl:template>
<xsl:template match="//dspace:dim">
<journal_article>
<!--
Title
http://www.crossref.org/help/schema_doc/4.3.6/common4_3_5_xsd.html#http___www.crossref.org_relations.xsd_titles
-->
<titles>
<xsl:apply-templates select="dspace:field[@mdschema='dc' and @element='title']" />
</titles>
<!--
Publication date
http://www.crossref.org/help/schema_doc/4.3.6/common4_3_5_xsd.html#http___www.crossref.org_relations.xsd_publication_date
-->
<publication_date>
<year>
<xsl:choose>
<xsl:when test="dspace:field[@mdschema='dc' and @element='date' and @qualifier='issued']">
<xsl:value-of select="substring(dspace:field[@mdschema='dc' and @element='date' and @qualifier='issued'], 1, 4)" />
</xsl:when>
<xsl:when test="dspace:field[@mdschema='dc' and @element='date' and @qualifier='available']">
<xsl:value-of select="substring(dspace:field[@mdschema='dc' and @element='date' and @qualifier='issued'], 1, 4)" />
</xsl:when>
<xsl:when test="dspace:field[@mdschema='dc' and @element='date']">
<xsl:value-of select="substring(dspace:field[@mdschema='dc' and @element='date'], 1, 4)" />
</xsl:when>
<xsl:otherwise>0000</xsl:otherwise>
</xsl:choose>
</year>
</publication_date>
<!--
DOI
http://www.crossref.org/help/schema_doc/4.3.6/common4_3_5_xsd.html#http___www.crossref.org_relations.xsd_doi_data
-->
<xsl:apply-templates select="dspace:field[@mdschema='dc' and @element='identifier' and starts-with(., 'https://doi.org/')]" />
</journal_article>
</xsl:template>
<!-- DOI -->
<xsl:template match="dspace:field[@mdschema='dc' and @element='identifier' and starts-with(., 'https://doi.org/')]">
<doi_data>
<doi><xsl:value-of select="substring(., 17)"/></doi>
<resource>
<xsl:value-of select="../dspace:field[@mdschema='dc'
and @element='identifier'
and @qualifier='uri'
and starts-with(., 'http://hdl.handle.net/')]"/>
</resource>
</doi_data>
</xsl:template>
<!-- Title -->
<xsl:template match="dspace:field[@mdschema='dc' and @element='title']">
<xsl:element name="title">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
@rivaldi8
Copy link
Author

rivaldi8 commented Aug 28, 2017

Usage:

  1. Extract DIM metadata through OAI. Use set to select the collection/community and from to select items published from that date.
wget -O articles.dim.xml "http://dspace-server/oai/request?verb=ListRecords&metadataPrefix=dim&set=col_1234_567&from=2017-05-09T07:10:47Z"
  1. Convert to Crossref XML:
java -classpath /usr/share/java/saxon.jar \
  com.icl.saxon.StyleSheet \
  articles.dim.xml dim2crossref.xsl > articles.crossref.xml
  1. Edit the resulting articles.crossref.xml:
  • Set the journal title at the node journal_metadata/full_title.
  • Set the ISSN at the node journal_metadata/issn.
  • If necessary, remove entries from items that got included in step 1 but you don't want to register for any reason.
  1. Validate the XML with the Crossref validator.
  2. Submit the XML through this form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment