Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Complete MODS => OAI DC transformation
<?xml version="1.0"?>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>Do Re Mi</dc:title>
</oai_dc:dc>
<xml>
<mods>
<titleInfo>
<title>Do Re Mi</title>
</titleInfo>
</mods>
</xml>
#!/usr/bin/env bash
# to actually transform the file you need some kind of program that can interpret an XSLT
# transform & `xsltproc` is available on Mac/Linux for this purpose, this is a shell script
# you could run on the command line to accomplish the transformation
xsltproc transform.xsl mods.xml > dublincore.xml
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/xml">
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<xsl:for-each select="mods/titleInfo/title">
<dc:title>
<xsl:value-of select="mods/titleInfo/title" />
</dc:title>
</xsl:for-each>
</oai_dc:dc>
</xsl:template>
</xsl:transform>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment