Skip to content

Instantly share code, notes, and snippets.

@sallain
Last active April 24, 2023 20:02
Show Gist options
  • Save sallain/7604ffb0c155294fcfaf to your computer and use it in GitHub Desktop.
Save sallain/7604ffb0c155294fcfaf to your computer and use it in GitHub Desktop.
MODS Template for Open Refine
<!-- For Prefix -->
<?xml version="1.0" encoding="UTF-8"?>
<modsCollection xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd">
<!-- For Row Template -->
<mods xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd">
<titleInfo>
<title>{{jsonize(cells["Title"].value)}}</title>
</titleInfo>
<name>
<namePart>{{jsonize(cells["Name"].value)}}</namePart>
<role>
<roleTerm type="text">{{jsonize(cells["Role"].value)}}</roleTerm>
</role>
</name>
<genre>{{jsonize(cells["Genre"].value)}}</genre>
<subject>
<topic>{{jsonize(cells["Subject"].value)}}</topic>
</subject>
<note>{{jsonize(cells["Note"].value)}}</note>
<originInfo>
<publisher>{{jsonize(cells["Publisher"].value)}}</publisher>
</originInfo>
<originInfo>
<dateCreated>{{jsonize(cells["Date"].value)}}</dateCreated>
</originInfo>
<physicalDescription>
<extent>{{jsonize(cells["Size"].value)}}</extent>
</physicalDescription>
<identifier type="local">{{jsonize(cells["Identifier"].value)}}</identifier>
<language>
<languageTerm type="text">{{jsonize(cells["Language"].value)}}</languageTerm>
</language>
<accessCondition>{{jsonize(cells["Rights"].value)}}</accessCondition>
</mods>
<!-- Don't put anything in Row Separator -->
<!-- For Suffix -->
</modsCollection>
@johnlevin2
Copy link

johnlevin2 commented Apr 24, 2016

A colleague of mine spent some time with her GREL skills, and she came up with this null value solution:

 {{if(isBlank(cells["Genre"].value),"","<genre>"+jsonize(cells["Genre"].value).replace('"', '')+"</genre>")}}

Here's a more complicated example for Subject Headings under authority:

  {{if(isBlank(cells["subj_auth_2"].value),"","<mods:subject authority="+jsonize(cells["subj_auth_2"].value)+">")}}
     {{if(isBlank(cells["subject_2"].value),"","<mods:topic>"+jsonize(cells["subject_2"].value).replace('"', '')+"</mods:topic>
  </mods:subject>")}}

@callyho
Copy link

callyho commented Jun 14, 2016

Thanks for posting and thanks dmj and psuda1 for the suggestions. I made a template for exporting to an EAD-formatted XML record and used the suggestions for removing the quotes as well as escaping the necessary characters (this is crucial for me as I'm working with metadata with ampersands galore).

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