This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mods_xml_merge.xsl
50 lines (43 loc) · 2.08 KB
/
mods_xml_merge.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.loc.gov/mods/v3" exclude-result-prefixes="xs mods #default" version="2.0"
xmlns="http://www.loc.gov/mods/v3"
xmlns:mods="http://www.loc.gov/mods/v3">
<!--
This stylesheet merges a directory of MODS XML files into a single XML file
with a modsCollection root element. Source document namespaces are omitted.
-->
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- USER: update the value with the path to the directory where the MODS XML files are located;
Note that the trailing slash must be present. -->
<xsl:param name="directoryName">
<xsl:text>sample_data/input_directory/</xsl:text>
</xsl:param>
<!-- Creates the root modsCollection element and calls XML documents in the named directory -->
<xsl:template match="/">
<modsCollection>
<xsl:apply-templates select="collection($directoryName)//mods"/>
</modsCollection>
</xsl:template>
<!-- Identity transform to copy the contents of each MODS XML file -->
<xsl:template match="@* | node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Specifically for MODS extracted with Islandora Datastream CRUD;
Extracts and formats the item PID using the filename of each MODS XML file;
Adds the PID as an identifier as the first element of the outputted MODS record.
-->
<xsl:template match="mods/*[1]">
<xsl:if test="contains(base-uri(.), '_MODS.xml')">
<identifier type="local" displayLabel="PID">
<xsl:value-of
select="replace(replace(substring-after(base-uri(.), $directoryName), '_MODS.xml', ''), '_', ':')"
/>
</identifier>
</xsl:if>
<xsl:copy-of select="." copy-namespaces="no"/>
</xsl:template>
</xsl:stylesheet>