Skip to content

Instantly share code, notes, and snippets.

@phette23
Created October 8, 2019 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/002a136fb92c22d0093ffb245937d2e6 to your computer and use it in GitHub Desktop.
Save phette23/002a136fb92c22d0093ffb245937d2e6 to your computer and use it in GitHub Desktop.
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