Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update mods_to_dc to v 1.8 (#102)
  • Loading branch information
bondjimbond authored and DiegoPino committed Feb 2, 2018
1 parent 3303ab3 commit 0a6e40e
Showing 1 changed file with 103 additions and 81 deletions.
184 changes: 103 additions & 81 deletions transforms/mods_to_dc.xsl
@@ -1,24 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mods="http://www.loc.gov/mods/v3" exclude-result-prefixes="mods"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:srw_dc="info:srw/schema/1/dc-schema"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mods="http://www.loc.gov/mods/v3" exclude-result-prefixes="mods" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:srw_dc="info:srw/schema/1/dc-schema" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--
Version 1.4 2015-01-30 schema location change:
<!--
Version 1.8 2015-03-05 tmee@loc.gov
Typo mods:provence changed to mods:province
Version 1.7 2015-01-30 ws
Changed dc:creator to dc:contributor if mods:name/mods:roleTerm != creator
Fixed xpath bug in dc:subject output for mods:subject/mods:titleInfo/mods:title
Fixed xpath bug in dc:format when mods:extent | mods:form | mods:internetMediaType [@unit]
Fixedbug in xpath for @type
Version 1.6 2015-01-30 schema location change:
http://www.loc.gov/standards/sru/recordSchemas/dc-schema.xsd
Version 1.5 2014-07-23 tmee@loc.gov
Fixed subject transformation to eliminate empty element output
Version 1.4 2013-12-13 tmee@loc.gov
Upgraded to MODS 3.5
Version 1.3 2013-12-09 tmee@loc.gov
Fixed date transformation for dates without start/end points
Fixed date transformation for dates without start/end points
Version 1.2 2012-08-12 WS
Upgraded to MODS 3.4
Upgraded to MODS 3.4
Revision 1.1 2007-05-18 tmee@loc.gov
Added modsCollection conversion to DC SRU
Updated introductory documentation
Version 1.1 2007-05-18 tmee@loc.gov
Added modsCollection conversion to DC SRU
Updated introductory documentation
Version 1.0 2007-05-04 tmee@loc.gov
Expand Down Expand Up @@ -46,30 +56,30 @@
-->

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<xsl:choose>
<!-- WS: updated schema location -->
<xsl:when test="//mods:modsCollection">
<srw_dc:dcCollection xsi:schemaLocation="info:srw/schema/1/dc-schema http://www.loc.gov/standards/sru/recordSchemas/dc-schema.xsd">
<xsl:apply-templates/>
<xsl:for-each select="mods:modsCollection/mods:mods">
<srw_dc:dc xsi:schemaLocation="info:srw/schema/1/dc-schema http://www.loc.gov/standards/sru/recordSchemas/dc-schema.xsd">
<xsl:apply-templates/>
</srw_dc:dc>
</xsl:for-each>
</srw_dc:dcCollection>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="mods:mods">
<oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<xsl:apply-templates/>
</oai_dc:dc>
</xsl:for-each>
</xsl:otherwise>
<xsl:when test="//mods:modsCollection">
<srw_dc:dcCollection xsi:schemaLocation="info:srw/schema/1/dc-schema http://www.loc.gov/standards/sru/recordSchemas/dc-schema.xsd">
<xsl:apply-templates/>
<xsl:for-each select="mods:modsCollection/mods:mods">
<srw_dc:dc xsi:schemaLocation="info:srw/schema/1/dc-schema http://www.loc.gov/standards/sru/recordSchemas/dc-schema.xsd">
<xsl:apply-templates/>
</srw_dc:dc>
</xsl:for-each>
</srw_dc:dcCollection>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="mods:mods">
<oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<xsl:apply-templates/>
</oai_dc:dc>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="mods:titleInfo">
<dc:title>
<xsl:value-of select="mods:nonSort"/>
Expand All @@ -92,16 +102,27 @@
</dc:title>
</xsl:template>

<!-- tmee mods 3.5 -->
<xsl:template match="mods:name">
<xsl:choose>
<xsl:when test="mods:role/mods:roleTerm[@type='text']='creator' or mods:role/mods:roleTerm[@type='code']='cre' ">
<dc:creator>
<xsl:call-template name="name"/>
<xsl:choose>
<xsl:when test="mods:etal">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:text>et al</xsl:text>
</xsl:otherwise>
</xsl:choose>
</dc:creator>
</xsl:when>
<xsl:otherwise>
<!-- ws 1.7 -->
<dc:contributor>
<xsl:call-template name="name"/>
<xsl:if test="mods:etal">et al.</xsl:if>
</dc:contributor>
</xsl:otherwise>
</xsl:choose>
Expand All @@ -113,44 +134,45 @@
</dc:subject>
</xsl:template>

<xsl:template match="mods:subject[mods:topic | mods:name | mods:occupation | mods:geographic | mods:hierarchicalGeographic | mods:cartographics | mods:temporal] ">
<dc:subject>
<xsl:for-each select="mods:topic | mods:occupation">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
<xsl:for-each select="mods:name">
<xsl:call-template name="name"/>
</xsl:for-each>
</dc:subject>

<xsl:for-each select="mods:titleInfo/mods:title">
<!-- ws 1.7 -->
<xsl:template match="mods:subject">
<xsl:if test="mods:topic | mods:occupation | mods:name">
<dc:subject>
<xsl:for-each select="mods:topic | mods:occupation">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
<xsl:for-each select="mods:name">
<xsl:call-template name="name"/>
</xsl:for-each>
</dc:subject>
</xsl:if>
<xsl:for-each select="mods:titleInfo">
<dc:subject>
<xsl:value-of select="mods:titleInfo/mods:title"/>
<xsl:for-each select="child::*">
<xsl:value-of select="."/>
<xsl:if test="following-sibling::*"><xsl:text> </xsl:text></xsl:if>
</xsl:for-each>
</dc:subject>
</xsl:for-each>

<xsl:for-each select="mods:geographic">
<dc:coverage>
<xsl:value-of select="."/>
</dc:coverage>
</xsl:for-each>

<xsl:for-each select="mods:hierarchicalGeographic">
<dc:coverage>
<xsl:for-each select="mods:continent|mods:country|mods:provence|mods:region|mods:state|mods:territory|mods:county|mods:city|mods:island|mods:area">
<xsl:for-each select="mods:continent|mods:country|mods:province|mods:region|mods:state|mods:territory|mods:county|mods:city|mods:island|mods:area">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
</xsl:for-each>
</dc:coverage>
</xsl:for-each>

<xsl:for-each select="mods:cartographics/*">
<dc:coverage>
<xsl:value-of select="."/>
</dc:coverage>
</xsl:for-each>

<xsl:if test="mods:temporal">
<dc:coverage>
<xsl:for-each select="mods:temporal">
Expand All @@ -159,7 +181,6 @@
</xsl:for-each>
</dc:coverage>
</xsl:if>

<xsl:if test="*[1][local-name()='topic'] and *[local-name()!='topic']">
<dc:subject>
<xsl:for-each select="*[local-name()!='cartographics' and local-name()!='geographicCode' and local-name()!='hierarchicalGeographic'] ">
Expand All @@ -178,22 +199,14 @@

<xsl:template match="mods:originInfo">
<xsl:apply-templates select="*[@point='start']"/>
<xsl:for-each
select="mods:dateIssued[@point!='start' and @point!='end'] |mods:dateCreated[@point!='start' and @point!='end'] | mods:dateCaptured[@point!='start' and @point!='end'] | mods:dateOther[@point!='start' and @point!='end']">
<dc:date>
<xsl:value-of select="."/>
</dc:date>
</xsl:for-each>
<xsl:apply-templates select="*[not(@point)]"/>

<xsl:apply-templates select="*[not(@point)]"/>
<xsl:for-each select="mods:publisher">
<dc:publisher>
<xsl:value-of select="."/>
</dc:publisher>
</xsl:for-each>

</xsl:template>

<xsl:template match="mods:dateIssued | mods:dateCreated | mods:dateCaptured">
<dc:date>
<xsl:choose>
Expand All @@ -210,18 +223,18 @@
</xsl:choose>
</dc:date>
</xsl:template>

<xsl:template match="mods:dateIssued[@point='start'] | mods:dateCreated[@point='start'] | mods:dateCaptured[@point='start'] | mods:dateOther[@point='start'] ">
<xsl:variable name="dateName" select="local-name()"/>
<dc:date>
<xsl:value-of select="."/>-<xsl:value-of select="../*[local-name()=$dateName][@point='end']"/>
</dc:date>
</xsl:template>

<xsl:template match="mods:temporal[@point='start'] ">
<xsl:value-of select="."/>-<xsl:value-of select="../mods:temporal[@point='end']"/>
</xsl:template>

<xsl:template match="mods:temporal[@point!='start' and @point!='end'] ">
<xsl:value-of select="."/>
</xsl:template>
Expand Down Expand Up @@ -283,11 +296,17 @@
<xsl:template match="mods:physicalDescription">
<xsl:for-each select="mods:extent | mods:form | mods:internetMediaType">
<dc:format>
<!-- tmee mods 3.5 -->
<xsl:variable name="unit" select="translate(@unit,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
<!-- ws 1.7 -->
<xsl:if test="@unit">
<xsl:value-of select="$unit"/>: 
</xsl:if>
<xsl:value-of select="."/>
</dc:format>
</xsl:for-each>
</xsl:template>
<!--
<!--
<xsl:template match="mods:mimeType">
<dc:format>
<xsl:value-of select="."/>
Expand All @@ -302,22 +321,27 @@
<xsl:when test="contains(.,':')">
<xsl:value-of select="."/>
</xsl:when>
<!-- ws 1.7 -->
<xsl:when test="@type">
<xsl:value-of select="$type"/>: <xsl:value-of select="."/>
</xsl:when>
<xsl:when test="contains ('isbn issn uri doi lccn uri', $type)">
<xsl:value-of select="$type"/>: <xsl:value-of select="."/>
<xsl:choose>
<xsl:when test="@type">
<xsl:value-of select="$type"/>: <xsl:value-of select="."/>
</xsl:when>
<xsl:when test="contains ('isbn issn uri doi lccn uri', $type)">
<xsl:value-of select="$type"/>: <xsl:value-of select="."/>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</dc:identifier>
</xsl:template>

<xsl:template match="mods:location">
<xsl:for-each select="mods:url">
<dc:identifier>
<dc:identifier>
<xsl:value-of select="."/>
</dc:identifier>
</xsl:for-each>
Expand All @@ -333,8 +357,7 @@
<xsl:choose>
<xsl:when test="@type='original'">
<dc:source>
<xsl:for-each
select="mods:titleInfo/mods:title | mods:identifier | mods:location/mods:url">
<xsl:for-each select="mods:titleInfo/mods:title | mods:identifier | mods:location/mods:url">
<xsl:if test="normalize-space(.)!= ''">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
Expand All @@ -345,8 +368,7 @@
<xsl:when test="@type='series'"/>
<xsl:otherwise>
<dc:relation>
<xsl:for-each
select="mods:titleInfo/mods:title | mods:identifier | mods:location/mods:url">
<xsl:for-each select="mods:titleInfo/mods:title | mods:identifier | mods:location/mods:url">
<xsl:if test="normalize-space(.)!= ''">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">--</xsl:if>
Expand All @@ -356,7 +378,7 @@
</xsl:otherwise>
</xsl:choose>
</xsl:template>



<xsl:template match="mods:accessCondition">
Expand Down Expand Up @@ -397,6 +419,6 @@

<!-- suppress all else:-->
<xsl:template match="*"/>
</xsl:stylesheet>


</xsl:stylesheet>

0 comments on commit 0a6e40e

Please sign in to comment.