Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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>
@ghost

ghost commented Sep 8, 2015

you can use .replace() after .value) to get rid of quotes if necessary.

Example {{jsonize(cells["Rights"].value).replace('"', '')}} (that's a single quotes with a double quote inside...comma...single quotes with nothing inside).

psuda1 - Thanks very much for adding the code to get rid of the quotes. After trying for several hours to figure out why we were getting the quotes in the first place, this line of code solved everything and our MODS xml file populated the record form perfectly.

Thanks again.
Monique -

@ghost

ghost commented Nov 2, 2015

How do you handle null values? In OpenRefine or prior to them?

dmj commented Mar 22, 2016

Why do you use jsonize() for the values? You are creating an XML document after all, so wouldn't

cells["Name"].value.escape("xml")

be better? Otherwise you get an error when a value contains a character that must be escaped (e.g. < or &).

Thank you, sallain, for your template and your blog post on the Digital Scholarship Unit blog!

Although I, like psuda1 am wondering how to remove null values, i.e. a cell with nothing in it?

johnlevin2 commented Apr 24, 2016 edited

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 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