-
Notifications
You must be signed in to change notification settings - Fork 0
/
htm-teidivapparatus.xsl
238 lines (207 loc) · 8.31 KB
/
htm-teidivapparatus.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id$ -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all" version="2.0">
<!-- only triggered if there is a <div type="apparatus"> (i.e. "external appartus") in the XML -->
<!--<xsl:import href="teidivapparatus.xsl"/>-->
<!-- Other div matches can be found in htm-teidiv.xsl -->
<xsl:param name="parm-internal-app-style" />
<xsl:param name="parm-external-app-style" />
<xsl:variable name="default-language" select="'en'"/>
<xsl:variable name="local-bibliography">
<xsl:if test="$parm-external-app-style = 'iospe'">
<xsl:for-each select="//t:div[@type='bibliography']//(t:bibl | t:biblStruct)">
<xsl:choose>
<xsl:when test="t:ptr/@target">
<!-- I know there is only one, we use for-each only to change context -->
<xsl:for-each select="t:ptr/@target">
<xsl:call-template name="source">
<xsl:with-param name="root" select="ancestor-or-self::t:TEI"/>
<xsl:with-param name="parm-external-app-style" select="'iospe'" tunnel="yes"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<t:ref>
<xsl:apply-templates select="." mode="parse-name-year"/>
</t:ref>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</xsl:variable>
<xsl:template name="source">
<xsl:param name="root"/>
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<xsl:variable name="source_location">
<xsl:choose>
<xsl:when
test="$root//t:encodingDesc//t:prefixDef[@ident] and $root//t:encodingDesc//t:prefixDef/@ident = substring-before(., ':')">
<xsl:value-of
select="replace(substring-after(., ':'),
$root//t:encodingDesc//t:prefixDef/@matchPattern,
$root//t:encodingDesc//t:prefixDef/@replacementPattern)"
/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<t:ref>
<xsl:choose>
<xsl:when test="$parm-external-app-style = 'iospe'">
<xsl:text>not collated</xsl:text>
</xsl:when>
<xsl:when test="starts-with($source_location, '#')">
<xsl:apply-templates
select="$root//t:div[@type='bibliography']//(t:bibl | t:biblStruct)[@xml:id=substring-after($source_location, '#')]"
mode="parse-name-year"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="document($source_location, $root)" mode="parse-name-year"/>
</xsl:otherwise>
</xsl:choose>
</t:ref>
</xsl:template>
<xsl:template name="sources">
<xsl:param name="root"/>
<!-- collect all sources -->
<xsl:variable name="sources">
<xsl:for-each select="tokenize(@source, ' ')">
<xsl:call-template name="source">
<xsl:with-param name="root" select="$root"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<!-- preselect sources to be printed -->
<xsl:variable name="final_printing_sources">
<xsl:for-each select="$sources/t:ref">
<xsl:variable name="n_authors_with_same_name_in_local_bib_and_current_sources"
select="count($local-bibliography/t:ref[t:name/text() = $sources/t:ref[t:name/text() = current()/t:name/text()]/t:name/text()])"/>
<xsl:variable name="n_authors_with_same_name_in_current_sources"
select="count($sources/t:ref[t:name/text() = current()/t:name/text()])"/>
<xsl:variable name="first_occurrence_of_this_author_in_sources"
select="$sources/t:ref[t:name/text() = current()/t:name/text()][1] = current()"/>
<xsl:variable name="n_authors_with_same_name_in_local_bib"
select="count($local-bibliography/t:ref[t:name/text() = current()/t:name/text()])"/>
<xsl:if
test="not($n_authors_with_same_name_in_local_bib_and_current_sources = $n_authors_with_same_name_in_current_sources)
or $first_occurrence_of_this_author_in_sources">
<t:ref>
<xsl:sequence select="./t:name"/>
<xsl:if
test="$n_authors_with_same_name_in_local_bib != 1
and not($n_authors_with_same_name_in_local_bib_and_current_sources = $n_authors_with_same_name_in_current_sources)">
<xsl:sequence select="./t:date"/>
</xsl:if>
</t:ref>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- print references -->
<xsl:text> </xsl:text>
<xsl:for-each select="$final_printing_sources/t:ref">
<xsl:value-of select="t:name"/>
<xsl:if test="t:date">
<xsl:text> </xsl:text>
<xsl:value-of select="t:date"/>
</xsl:if>
<xsl:if test="not(position() = last())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="t:bibl | t:biblStruct" mode="parse-name-year">
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<t:name>
<xsl:for-each select=".//t:author[1]">
<xsl:choose>
<xsl:when test=".//t:surname">
<xsl:value-of select=".//t:surname[@xml:lang=$default-language or not(@xml:lang)]"/>
</xsl:when>
<xsl:when test=".//t:forename">
<xsl:value-of select=".//t:forename[@xml:lang=$default-language or not(@xml:lang)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</t:name>
<t:date>
<xsl:choose>
<xsl:when test=".//t:imprint[1]">
<xsl:value-of select=".//t:imprint[1]//t:date"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=".//t:date[1]"/>
</xsl:otherwise>
</xsl:choose>
</t:date>
</xsl:template>
<xsl:template match="t:div[@type='apparatus']" priority="1">
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<div id="apparatus">
<h2>apparatus</h2>
<p>
<xsl:apply-templates/>
</p>
</div>
</xsl:template>
<xsl:template match="t:div[@type='apparatus']//t:app">
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<span>
<xsl:attribute name="class">
<xsl:value-of select="@loc"/>
</xsl:attribute>
<xsl:if
test="@loc and (not(preceding-sibling::t:app) or @loc != preceding-sibling::t:app[1]/@loc)">
<xsl:value-of select="translate(@loc, ' ', '.')"/>
<xsl:text>: </xsl:text>
</xsl:if>
<xsl:apply-templates/>
</span>
<xsl:choose>
<xsl:when test="@loc != following-sibling::t:app[1]/@loc">
<br/>
</xsl:when>
<xsl:when test="following-sibling::t:app">
<xsl:text>; </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="t:div[@type = 'apparatus']//t:rdg">
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<xsl:apply-templates/>
<xsl:call-template name="sources">
<xsl:with-param name="root" select="ancestor-or-self::t:TEI"/>
</xsl:call-template>
<xsl:if test="following-sibling::t:rdg and not(following-sibling::*[1][self::t:note])">
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="t:div[@type = 'apparatus']//t:lem">
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<xsl:apply-templates/>
<xsl:call-template name="sources">
<xsl:with-param name="root" select="ancestor-or-self::t:TEI"/>
</xsl:call-template>
<xsl:if
test="following-sibling::t:* and not(following-sibling::t:*[1][self::t:note]) and not(@source)">
<xsl:text>: </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="t:div[@type = 'apparatus']//t:note">
<xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
<span>
<xsl:if test="ancestor::t:app">
<xsl:apply-templates/>
<xsl:if test="preceding-sibling::t:rdg and following-sibling::t:rdg">
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:if>
</span>
</xsl:template>
</xsl:stylesheet>