moa2mets.xsl: An XSLT to convert MOA2 to METS

This document provides some examples demonstrating the use of an XSLT style sheet to convert MOA2 to METS.

Summary

xsltproc -o output.mets.xml moa2mets.xsl input.moa2.xml

Sample Files

MOA2METSXSLT
brk00010.00000004.xml brk00010.00000004.mets.xml moa2mets.xsl
brk00007.00000149c.xml brk00007.00000149c.mets.xml moa2mets.xsl
csr9.xml csr9.mets.xml moa2mets.xsl
48.xml 48.mets.xml moa2mets.date.xsl

Dependencies

In addition to the METS XML Schema and the xlink XML Schema required by METS, the METS produced by this XSLT make use of a "MOA2 metadata" XML Schema.  This schema was created by opening the MOA2 DTD in XML Spy, saving as an XML Schema, and then adding an "xy" element to hold the X, Y, UNITS, and USE attributes which are no longer allowed in the METS file elements.

The XSLT was tested with The XSLT C library for Gnome's xsltproc.  This should be installed already if you are using gnome as your desktop; alternatively it is easy to install.  The XSLT should work with any XSLT processor.  xsltproc will look for MOA2.DTD unless you give if the --novalid flag.

Date/time reformatting requires http://www.exslt.org/date/functions/parse-date/date.parse-date.template.xsl

An example wherein dates are encoded sort of like XML Schema valid dates

If the VERSDATE attribute of FileGrp elements and the CREATED attribute of File elements in your MOA2 file look like an XML Schema valid xs:dateTime; "CCYY-MM-DDThh:mm:ss" or "CCYY-MM-DD hh:mm:ss"; then you may use the XSLT style sheet as is to create valid XML.

xsltproc -o brk00010.00000004.mets.xml moa2mets.xsl brk00010.00000004.xml
 

An example wherein dates are encoded like mm/dd/yyyy

In order to reformat date string from some random date format to XML Schema valid dates, it is necessary to use EXSLT - date:parse-date.

Take for example, 48.xml.  This MOA2 has dates that look like "12/3/1998" and "3/1/1998". moa2mets.date.xsl will convert dates in this format.

xsltproc -o 48.mets.xml moa2mets.date.xsl 48.xml

MOA2 documents which use other date time encoding formats

Examine the difference between moa2mets.xsl and moa2mets.date.xsl

diff moa2mets.xsl moa2mets.date.xsl
5c5,12
<                                      version="1.0">
---
>                                      version="1.0"
> xmlns:date="http://exslt.org/dates-and-times"
> extension-element-prefixes="date">
>
> <xsl:import href="date.parse-date.template.xsl" />
>
>
>
168,170c175,186
<               <xsl:attribute name="CREATED"><xsl:value-of
<                       select="substring(.,1,10)"/>T<xsl:value-of
<                       select="substring(.,12)"/>
---
> <xsl:variable name="date"><xsl:value-of select="."/></xsl:variable>
>               <xsl:attribute name="CREATED">
>     <xsl:call-template name="date:parse-date">
>       <xsl:with-param name="date-time" select="$date" />
>       <xsl:with-param name="format" select="'M/d/yyyy'" />
>       <xsl:with-param name="hour" select="0" />
>     </xsl:call-template>
>     <xsl:call-template name="date:parse-date">
>       <xsl:with-param name="date-time" select="$date" />
>       <xsl:with-param name="format" select="'MM/d/yyyy'" />
>       <xsl:with-param name="hour" select="0" />
>     </xsl:call-template>
189,193c205,218
<               <xsl:attribute name="VERSDATE"><xsl:value-of
<                       select="substring(.,1,10)"/>T<xsl:value-of
<                       select="substring(.,12)"/>
<               </xsl:attribute>
<       </xsl:when>
---
> <xsl:variable name="date"><xsl:value-of select="."/></xsl:variable>
>         <xsl:attribute name="VERDATE">
>     <xsl:call-template name="date:parse-date">
>       <xsl:with-param name="date-time" select="$date" />
>       <xsl:with-param name="format" select="'M/d/yyyy'" />
>       <xsl:with-param name="hour" select="0" />
>     </xsl:call-template>
>     <xsl:call-template name="date:parse-date">
>       <xsl:with-param name="date-time" select="$date" />
>       <xsl:with-param name="format" select="'MM/d/yyyy'" />
>       <xsl:with-param name="hour" select="0" />
>     </xsl:call-template>
>         </xsl:attribute>
>     </xsl:when>

Edit the XSLT call-template parameters to match your data. Please see EXSLT - date:parse-date for more information on turning arbitrary date encodings into valid xs:dateTime with XSLT.

Validating the resultant METS files

I use Xerces2 Java to validate XML files.
With xercesImpl.jar, xercesSamples.jar and  xmlParserAPIs.jar in your classpath
java -mx64M sax.Counter -np -v -s file.mets.xml

Support

This XSLT has been tested on a few Berkeley MOA2 files.  While the CDL offers this XSLT transformation as is, if you encounter situations where this does not produce valid XML please report the problem to me and I may be able to offer a suggestion.