-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrespDesc-transform.xsl
160 lines (123 loc) · 5.96 KB
/
correspDesc-transform.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:c8r="http://www.digitale-akademie.de/cmiferator" exclude-result-prefixes="#all" version="3.0">
<!--
(:
: CMIFerator
:
: Developed by Julian Jarosch
: Academy of Sciences and Literature | Mainz
: Digital Academy
:
: Stylesheet for transforming TEI P5 to the CMIF subset.
:
: @author Julian Jarosch
: @email <Julian.Jarosch@adwmainz.de>
: @licence MIT
:)
-->
<!-- O P T I O N S -->
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<!-- P A R A M E T E R S -->
<!-- get configuration file path -->
<xsl:param name="config-filepath"/>
<!-- V A R I A B L E S -->
<!-- load configuration file -->
<xsl:variable name="config" select="doc($config-filepath)/c8r:configuration"/>
<xsl:variable name="unknown"><xsl:text>Unbekannt</xsl:text></xsl:variable>
<!-- T E M P L A T E S -->
<!-- root -->
<xsl:template match="/">
<!-- this specifies the “usual” practice and might potentially exclude TEI Corpus or TEI nested within tei:text -->
<xsl:apply-templates select="tei:TEI/tei:teiHeader/tei:profileDesc/tei:correspDesc"/>
</xsl:template>
<!-- correspDesc -->
<xsl:template match="tei:correspDesc[1]">
<correspDesc xmlns="http://www.tei-c.org/ns/1.0" source="#{$config/c8r:header/c8r:uuid/child::text()}">
<xsl:attribute name="ref">
<!-- concatenate the permalink from a namespace / base URL and the xml:id of the file -->
<!-- TODO: it may be better to not do this, and instead take the complete permalink from an <idno> within the file -->
<!-- if the latter, that may need to be configured using an XPath -->
<xsl:value-of select="$config/c8r:namespace/child::text() || ./ancestor::tei:TEI/@xml:id"/>
</xsl:attribute>
<!-- correspAction[@type = 'sent'] must always be included -->
<xsl:if test="not(tei:correspAction[@type = 'sent'])">
<correspAction type="sent">
<persName><xsl:value-of select="$unknown"/></persName>
</correspAction>
</xsl:if>
<!-- correspAction[@type = 'received'] must always be included -->
<xsl:if test="not(tei:correspAction[@type = 'received'])">
<correspAction type="received">
<persName><xsl:value-of select="$unknown"/></persName>
</correspAction>
</xsl:if>
<xsl:apply-templates select="tei:correspAction"/>
</correspDesc>
</xsl:template>
<!-- only keep one correspDesc per file (pick the first one) -->
<xsl:template match="tei:correspDesc[position() > 1]"/>
<!-- correspAction -->
<xsl:template match="tei:correspAction">
<!-- only correspActions sent and received are allowed in CMIF – discard all others -->
<xsl:if test="@type = ('sent', 'received')">
<xsl:variable name="type" select="@type"/>
<correspAction xmlns="http://www.tei-c.org/ns/1.0" type="{$type}">
<!-- if no persName element is present, a “dummy” element with a fixed content needs to be inserted -->
<xsl:if test="not(tei:persName)">
<persName><xsl:value-of select="$unknown"/></persName>
</xsl:if>
<xsl:apply-templates select="(tei:date | tei:persName | tei:orgName | tei:placeName)"/>
</correspAction>
</xsl:if>
</xsl:template>
<!-- date -->
<xsl:template match="tei:date[1]">
<!-- check if any of the dating attributes are present and not empty -->
<xsl:if test="normalize-space(string-join(@when | @notBefore | @notAfter | @from | @to))">
<date xmlns="http://www.tei-c.org/ns/1.0">
<!-- only retain allowed attributes -->
<xsl:for-each select="(@when | @notBefore | @notAfter | @from | @to)">
<!-- only three types of notation are allowed – discard all others -->
<!-- TODO: when none of the attributes conform, the resulting date element is empty -->
<xsl:if test="matches(., '^\d{4}(-\d{2}){0,2}$')">
<xsl:copy/>
</xsl:if>
</xsl:for-each>
</date>
</xsl:if>
</xsl:template>
<!-- only keep one date per correspAction (pick the first one) -->
<xsl:template match="tei:correspAction/tei:date[position() > 1]"/>
<!-- persName -->
<xsl:template match="tei:persName">
<persName xmlns="http://www.tei-c.org/ns/1.0">
<xsl:if test="normalize-space(@ref)">
<xsl:attribute name="ref">
<xsl:value-of select="@ref"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</persName>
</xsl:template>
<!-- orgName -->
<xsl:template match="tei:orgName">
<orgName xmlns="http://www.tei-c.org/ns/1.0">
<xsl:if test="normalize-space(@ref)">
<xsl:attribute name="ref">
<xsl:value-of select="@ref"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</orgName>
</xsl:template>
<!-- placeName -->
<xsl:template match="tei:placeName">
<placeName xmlns="http://www.tei-c.org/ns/1.0">
<xsl:if test="normalize-space(@ref)">
<xsl:attribute name="ref">
<xsl:value-of select="@ref"/>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</placeName>
</xsl:template>
</xsl:stylesheet>