-
Notifications
You must be signed in to change notification settings - Fork 1
/
teibp_pb.xsl
215 lines (209 loc) · 10.8 KB
/
teibp_pb.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xsl tei xd eg #default" version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:eg="http://www.tei-c.org/ns/Examples"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- construct the image URL on the fly -->
<xsl:variable name="v_volume" select="$vgBiblStructSource/tei:monogr/tei:biblScope[@unit = 'volume']/@n"/>
<xsl:variable name="v_issue" select="$vgBiblStructSource/tei:monogr/tei:biblScope[@unit = 'issue']/@n"/>
<!-- IIIF URLs: establish the pattern to check for -->
<xsl:variable name="v_iiif-settings-max" select="'/full/2000,/0/default.jpg'"/>
<!-- could also select pb[@facs] -->
<xsl:template match="tei:pb[@ed = 'print']">
<xsl:choose>
<xsl:when test="$p_display-page-breaks = true()">
<!-- add @lang="en" to ensure correct ltr rendering -->
<xsl:call-template name="t_handler-pb">
<xsl:with-param name="p_pb" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="t_handler-pb">
<xsl:param name="p_pb"/>
<xsl:variable name="v_facs" select="$p_pb/@facs"/>
<xsl:variable name="v_id">
<xsl:choose>
<xsl:when test="$p_pb/@xml:id">
<xsl:value-of select="$p_pb/@xml:id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="generate-id()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="v_id-facs" select="substring-after($v_facs, '#')"/>
<xsl:variable name="v_graphic" select="ancestor::tei:TEI/tei:facsimile/tei:surface[@xml:id = $v_id-facs]/tei:graphic"/>
<!-- select which online facsimile to display based on the order of preference: EAP, sakhrit, HathiTrust, other; and https over http -->
<xsl:variable name="v_url-graphic">
<xsl:choose>
<!-- sequence of providers and protocolls is currently hardcoded and can be changed to taste -->
<!-- iiif -->
<xsl:when test="$v_graphic[contains(@url, $v_iiif-settings-max)]">
<xsl:value-of select="concat(substring-before($v_graphic[contains(@url, $v_iiif-settings-max)][1]/@url, $v_iiif-settings-max), $p_iiif-settings-display)"/>
</xsl:when>
<xsl:when test="$v_graphic[@type='iiif']">
<xsl:value-of select="concat($v_graphic[@type='iiif'][1]/@url, $p_iiif-settings-display)"/>
</xsl:when>
<xsl:when test="$v_graphic[starts-with(@url, 'https://eap.')]">
<xsl:value-of select="$v_graphic[starts-with(@url, 'https://eap.')][1]/@url"/>
</xsl:when>
<xsl:when test="$v_graphic[starts-with(@url, 'http://eap.')]">
<xsl:value-of select="$v_graphic[starts-with(@url, 'http://eap.')][1]/@url"/>
</xsl:when>
<xsl:when test="$v_graphic[contains(@url, 'archive.alsharekh.org/')]">
<xsl:value-of select="$v_graphic[contains(@url, 'archive.alsharekh.org/')][1]/@url"/>
</xsl:when>
<xsl:when test="$v_graphic[contains(@url, 'archive.sakhrit.co')]">
<xsl:value-of select="$v_graphic[contains(@url, 'archive.sakhrit.co')][1]/@url"/>
</xsl:when>
<xsl:when test="$v_graphic[starts-with(@url, 'https://babel.hathitrust.org')]">
<xsl:value-of select="$v_graphic[starts-with(@url, 'https://babel.hathitrust.org')][1]/@url"/>
</xsl:when>
<xsl:when test="$v_graphic[starts-with(@url, 'http://babel.hathitrust.org')]">
<xsl:value-of select="$v_graphic[starts-with(@url, 'http://babel.hathitrust.org')][1]/@url"/>
</xsl:when>
<xsl:when test="$v_graphic[starts-with(@url, 'https')]">
<xsl:value-of select="$v_graphic[starts-with(@url, 'https')][1]/@url"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$v_graphic[starts-with(@url, 'http')][1]/@url"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- dealing with pointers instead of full URLs in @facs -->
<xsl:variable name="v_url-facs">
<xsl:choose>
<xsl:when test="starts-with($v_facs, '#')">
<!-- Preference: -->
<xsl:choose>
<!-- display of local facsimiles -->
<xsl:when test="$p_display-online-facsimiles = false()">
<!-- set preferences for mimeTypes -->
<xsl:choose>
<!-- test for $p_mimetype -->
<xsl:when test="$v_graphic[not(starts-with(@url,'http'))]/@mimeType = $p_mimetype">
<xsl:value-of select="$v_graphic[not(starts-with(@url,'http'))][@mimeType = $p_mimetype][1]/@url"/>
</xsl:when>
<!-- fallback to JPG -->
<xsl:otherwise>
<xsl:value-of select="$v_graphic[not(starts-with(@url,'http'))][@mimeType = 'image/jpeg'][1]/@url"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- select the online copy as default -->
<xsl:otherwise>
<xsl:value-of select="$v_url-graphic"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$v_facs"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="v_url-facs-online">
<xsl:choose>
<xsl:when test="starts-with($v_facs, '#')">
<xsl:value-of select="$v_url-graphic"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$v_facs"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- constructing a link for every graphic element -->
<xsl:variable name="v_facs-links">
<xsl:for-each select="$v_graphic[starts-with(@url, 'http')]">
<a target="_blank">
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="contains(@url, $v_iiif-settings-max)">
<xsl:value-of select="concat(substring-before(@url, $v_iiif-settings-max), $p_iiif-settings-display)"/>
</xsl:when>
<xsl:when test="@type='iiif'">
<xsl:value-of select="concat(@url, $p_iiif-settings-display)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@url"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:call-template name="t_url-to-name">
<xsl:with-param name="p_input" select="@url"/>
</xsl:call-template>
</a>
<xsl:if test="position()!=last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- construct the final output -->
<span class="c_teibp-pb" lang="en">
<xsl:call-template name="addID"/>
<!-- span to draw a horizontal divider -->
<span class="c_teibp-pbLine"> </span>
<!-- span to act as container for information and facsimiles-->
<span>
<xsl:attribute name="class">
<xsl:text>c_teibp-pbImgInfo </xsl:text>
<xsl:choose>
<xsl:when test="$p_facsimile-only = true()">
<xsl:text>c_facsimily-only</xsl:text>
</xsl:when>
<xsl:when test="$p_facsimile-only = false()">
<xsl:text>c_text-and-facsimily</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:attribute>
<!-- span containing all information on the page and the facsimile -->
<span class="c_teibp-pageNum" lang="{$v_lang-interface}">
<!-- this should be a back-link -->
<a class="c_link-self" href="{concat('#',$v_id)}" title="{concat($p_text-permalink,$p_text-name-element_pb)}">
<xsl:copy-of select="$p_text-page"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$p_pb/@n"/>
</a>
<!-- provide link to online facsimile no matter what -->
<xsl:if test="$v_facs = true()">
<xsl:text> - </xsl:text>
<xsl:copy-of select="$p_text-facs-link"/>
<xsl:text> </xsl:text>
<xsl:copy-of select="$v_facs-links"/>
</xsl:if>
</span>
<!-- span containing the actual image -->
<xsl:if test="$v_facs = true()">
<span class="c_teibp-pbFacs" lang="en">
<a class="gallery-facs" lang="en" href="{$v_url-facs}" target="_blank">
<img src="{$v_url-facs}" class="c_teibp-thumbnail"/>
</a>
</span>
</xsl:if>
</span>
</span>
</xsl:template>
<xsl:template name="t_url-to-name">
<xsl:param name="p_input"/>
<xsl:choose>
<xsl:when test="contains($p_input, 'eap.')">
<span lang="en">EAP</span>
</xsl:when>
<xsl:when test="contains($p_input, 'archive.sakhrit.co')">
<span lang="en">archive.sakhrit.co</span>
</xsl:when>
<xsl:when test="contains($p_input, 'hathitrust.')">
<span lang="en">HathiTrust</span>
</xsl:when>
<xsl:otherwise>
<span lang="en"><xsl:value-of select="substring-before(substring-after($p_input,'://'),'/')"/></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>