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="" xmlns:xsi="" xsi:schemaLocation="">
<!-- For Row Template -->
<mods xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<roleTerm type="text">{{jsonize(cells["Role"].value)}}</roleTerm>
<identifier type="local">{{jsonize(cells["Identifier"].value)}}</identifier>
<languageTerm type="text">{{jsonize(cells["Language"].value)}}</languageTerm>
<!-- Don't put anything in Row Separator -->
<!-- For Suffix -->

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


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

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>

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