forked from fordmadox/schematrons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EAD_add_IDs_to_containers.xsl
37 lines (32 loc) · 1.5 KB
/
EAD_add_IDs_to_containers.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ead="urn:isbn:1-931666-22-9"
version="1.0">
<!-- FYI: if your EAD files are not in the EAD namespace, then you will need to change the last two template @match
attributes from ead:container to container -->
<!--standard identity template, which does all of the copying-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--adds an @id attribute to the first container element that doesn't already have an @id or @parent attribute-->
<xsl:template match="ead:container[not(@id|@parent)][1]">
<xsl:copy>
<xsl:attribute name="id">
<xsl:value-of select="generate-id()"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--adds a @parent attribute to the following container elements that don't already have an @Id or @parent attribute-->
<xsl:template match="ead:container[not(@id|@parent)][position() > 1]">
<xsl:copy>
<xsl:attribute name="parent">
<xsl:value-of select="generate-id(../ead:container[not(@id|@parent)][1])"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>