-
Notifications
You must be signed in to change notification settings - Fork 12
/
htm-teibibl.xsl
345 lines (291 loc) · 14.1 KB
/
htm-teibibl.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:f="http://example.com/ns/functions"
xmlns:html="http://www.w3.org/1999/html" exclude-result-prefixes="t f" version="2.0" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:import href="htm-teilistbiblandbibl.xsl"/>
<!--
Pietro notes on 14/8/2015 work on this template, from mail to Gabriel.
- I have converted the TEI bibliography of IRT and IGCyr to ZoteroRDF
(https://github.com/EAGLE-BPN/BiblioTEI2ZoteroRDF) in this passage I have tried to
distinguish books, bookparts, articles and conference proceedings.
- I have uploaded these to the zotero eagle open group bibliography
(https://www.zotero.org/groups/eagleepigraphicbibliography)
- I have created a parametrized template in my local epidoc xslts which looks at the json
and TEI output of the Zotero api basing the call on the content of ptr/@target in each
bibl. It needs both because the key to build the link is in the json but the TEI xml is
much more accessible for the other data. I tried also to grab the html div exposed in the
json, which would have been the easiest thing to do, but I can only get it escaped and
thus is not usable.
** If set on 'zotero' it prints surname, name, title and year with a link to the zotero
item in the eagle group bibliography. It assumes bibl only contains ptr and citedRange.
** If set on 'localTEI' it looks at a local bibliography (no zotero) and compares the
@target to the xml:id to take the results and print something (in the sample a lot, but
I'd expect more commonly Author-Year references(.
** I have also created sample values for irt and igcyr which are modification of the
zotero option but deal with some of the project specific ways of encoding the
bibliography. All examples only cater for book and article.
-->
<!--
Pietro Notes on 10.10.2016
this should be modified based on parameters to
* decide wheather to use zotero or a local version of the bibliography in TEI
* assuming that the user has entered a unique tag name as value of ptr/@target, decide group or user in zotero to look up based on parameter value entered at transformation time
* output style based on Zotero Style Repository stored in a parameter value entered at transformation time
-->
<xsl:template match="t:bibl" priority="1">
<xsl:param name="parm-bib" tunnel="yes" required="no"/>
<xsl:param name="parm-bibloc" tunnel="yes" required="no"/>
<xsl:param name="parm-zoteroUorG" tunnel="yes" required="no"/>
<xsl:param name="parm-zoteroKey" tunnel="yes" required="no"/>
<xsl:param name="parm-zoteroNS" tunnel="yes" required="no"/>
<xsl:param name="parm-zoteroStyle" tunnel="yes" required="no"/>
<xsl:choose>
<!-- default general zotero behaviour prints
author surname and name, title in italics, date and links to the zotero item page on the zotero bibliography.
assumes the inscription source has no free text in bibl,
!!!!!!!only a <ptr target='key'/> and a <citedRange>pp. 45-65</citedRange>!!!!!!!
it also assumes that the content of ptr/@target is a unique tag used in the zotero bibliography as the ids assigned by Zotero are not
reliable enough for this purpose according to Zotero forums.
if there is no ptr/@target, this will try anyway and take a lot of time.
-->
<xsl:when test="$parm-bib = 'none'">
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="$parm-bib = 'zotero'">
<xsl:choose>
<!-- check if there is a ptr at all
WARNING. if the pointer is not there, the transformation will simply stop and return a premature end of file message e.g. it cannot find what it is looking for via the zotero api
-->
<xsl:when test=".[t:ptr]">
<!-- check if a namespace is provided for tags/xml:ids and use it as part of the tag for zotero-->
<xsl:variable name="biblentry"
select="
if ($parm-zoteroNS)
then
concat($parm-zoteroNS, ./t:ptr/@target)
else
./t:ptr/@target"/>
<xsl:variable name="zoteroapitei">
<xsl:value-of
select="concat('https://api.zotero.org/',$parm-zoteroUorG,'/',$parm-zoteroKey,'/items?tag=', $biblentry, '&format=tei')"/>
<!-- to go to the json with the escaped html included use &format=json&include=bib,data and the code below: the result is anyway escaped... -->
</xsl:variable>
<xsl:variable name="zoteroapijson">
<xsl:value-of
select="concat('https://api.zotero.org/',$parm-zoteroUorG,'/',$parm-zoteroKey,'/items?tag=', $biblentry, '&format=json&style=',$parm-zoteroStyle,'&include=citation')"
/>
</xsl:variable>
<xsl:variable name="unparsedtext" select="unparsed-text($zoteroapijson)"/>
<xsl:variable name="zoteroitemKEY">
<xsl:analyze-string select="$unparsedtext"
regex="(\[\s+\{{\s+"key":\s")(.+)"">
<xsl:matching-substring>
<xsl:value-of select="regex-group(2)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:choose>
<!--this will print a citation according to the selected style with a link around it pointing to the resource DOI, url or zotero item view-->
<xsl:when test="not(ancestor::t:div[@type = 'bibliography'])">
<xsl:variable name="pointerurl">
<xsl:choose>
<xsl:when
test="document($zoteroapitei)//t:idno[@type = 'DOI']">
<xsl:value-of
select="document($zoteroapitei)//t:idno[@type = 'DOI']"
/>
</xsl:when>
<xsl:when
test="document($zoteroapitei)//t:idno[@type = 'url']">
<xsl:value-of
select="document($zoteroapitei)//t:idno[@type = 'url']"
/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="document($zoteroapitei)//t:biblStruct/@corresp"
/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="{$pointerurl}">
<xsl:variable name="citation">
<xsl:analyze-string select="$unparsedtext"
regex="(\s+"citation":\s"<span>)(.+)(</span>")">
<xsl:matching-substring>
<xsl:value-of select="regex-group(2)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:value-of select="$citation"/>
<xsl:if test="t:citedRange">
<xsl:text>, </xsl:text>
<xsl:value-of select="t:citedRange"/>
</xsl:if>
</a>
</xsl:when>
<!-- if it is in the bibliography print styled reference-->
<xsl:otherwise>
<!-- print out using Zotoro parameter format with value bib and the selected style-->
<xsl:copy-of
select="document(concat('https://api.zotero.org/',$parm-zoteroUorG,'/',$parm-zoteroKey,'/items?tag=', $biblentry, '&format=bib&style=',$parm-zoteroStyle))/div"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- if there is no ptr, print simply what is inside bibl and a warning message-->
<xsl:otherwise>
<xsl:value-of select="."/>
<xsl:message>There is no ptr with a @target in the bibl element <xsl:copy-of
select="."/>. A target equal to a tag in your zotero bibliography is
necessary.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!--uses the local TEI bibliography at the path specified in parameter parm-bibloc -->
<xsl:when test="$parm-bib = 'localTEI'">
<xsl:variable name="biblentry" select="./t:ptr/@target"/>
<xsl:variable name="biblentryID" select="substring-after(./t:ptr/@target, '#')"/>
<!-- parameter localbibl should contain the path to the bibliography relative to this xslt -->
<xsl:variable name="textref"
select="document(string($parm-bibloc))//t:bibl[@xml:id = $biblentryID]"/>
<xsl:for-each select="$biblentry">
<xsl:choose>
<!--this will print a citation according to the selected style with a link around it pointing to the resource DOI, url or zotero item view-->
<xsl:when test="not(ancestor::t:div[@type = 'bibliography'])">
<!-- basic render for citations-->
<xsl:choose>
<xsl:when test="$textref/@xml:id = $biblentryID">
<xsl:choose>
<xsl:when test="$textref//t:author">
<xsl:value-of select="$textref//t:author[1]"/>
<xsl:if test="$textref//t:author[2]">
<xsl:text>-</xsl:text>
<xsl:value-of select="$textref//t:author[2]"/>
</xsl:if>
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test="$textref//t:editor">
<xsl:value-of select="$textref//t:editor[1]"/>
<xsl:if test="$textref//t:editor[2]">
<xsl:text>-</xsl:text>
<xsl:value-of select="$textref//t:editor[2]"/>
</xsl:if>
</xsl:when>
</xsl:choose>
<xsl:text> (</xsl:text>
<xsl:value-of select="$textref//t:date"/>
<xsl:text>), </xsl:text>
<xsl:value-of select="$textref//t:biblScope"/>
</xsl:when>
<xsl:otherwise>
<!--if this appears the id do not really correspond to each other,
ther might be a typo or a missing entry in the bibliography-->
<xsl:message>
<xsl:text> there is no entry in your bibliography file at </xsl:text>
<xsl:value-of select="$parm-bibloc"/>
<xsl:text> with the @xml:id</xsl:text>
<xsl:value-of select="$biblentry"/>
<xsl:text>!</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- rudimental render for each entry in bibliography-->
<xsl:choose>
<xsl:when test="$textref/@xml:id = $biblentryID">
<xsl:value-of select="$textref"/>
<!--assumes a sligthly "formatted" bibliography...-->
</xsl:when>
<xsl:otherwise>
<!--if this appears the id do not really correspond to each other,
ther might be a typo or a missing entry in the bibliography-->
<xsl:message>
<xsl:text> there is no entry in your bibliography file at </xsl:text>
<xsl:value-of select="$parm-bibloc"/>
<xsl:text> for the entry </xsl:text>
<xsl:value-of select="$biblentry"/>
<xsl:text>!</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<!-- This applyes other templates and does not call the zotero api -->
<!--<xsl:apply-templates/>-->
<xsl:apply-imports/> <!-- so that the templates in 'htm-teilistbiblandbibl.xsl are applied (li aroub bibl elements) -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="t:ptr[@target]">
<xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
<xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
<xsl:choose>
<!-- MODIFIED for SigiDoc by MS 2023-06-16 -->
<xsl:when test=" $parm-leiden-style = 'medcyprus' or $parm-edn-structure='inslib' or $parm-edn-structure='sample' or $parm-edn-structure='sigidoc'">
<!-- if you are running this template outside EFES, change the path to the bibliography authority list accordingly -->
<xsl:variable name="bibliography-al" select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/bibliography.xml')"/>
<xsl:variable name="bibl-ref" select="translate(@target, '#', '')"/>
<xsl:choose>
<xsl:when test="doc-available($bibliography-al) = fn:true()">
<xsl:variable name="bibl" select="document($bibliography-al)//t:bibl[@xml:id=$bibl-ref][not(@sameAs)]"/>
<a href="../concordance/bibliography/{$bibl-ref}.html" target="_blank">
<xsl:choose>
<xsl:when test="$bibl//t:bibl[@type='abbrev']">
<xsl:apply-templates select="$bibl//t:bibl[@type='abbrev'][1]"/>
</xsl:when>
<xsl:when test="$bibl//t:title[@type='short']">
<xsl:apply-templates select="$bibl//t:title[@type='short'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$bibl[ancestor::t:div[@xml:id='series_collections']]">
<i><xsl:value-of select="$bibl/@xml:id"/></i>
</xsl:when>
<xsl:when test="$bibl[ancestor::t:div[@xml:id='authored_editions']] or ($bibl//t:name[@type='surname'] and $bibl//t:date)">
<xsl:for-each select="$bibl//t:name[@type='surname'][not(parent::*/preceding-sibling::t:title[not(@type='short')])]">
<xsl:apply-templates select="."/>
<xsl:if test="position()!=last()"> – </xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
<xsl:apply-templates select="$bibl//t:date"/>
</xsl:when>
<xsl:when test="$bibl//t:surname and $bibl//t:date">
<xsl:for-each select="$bibl//t:surname[not(parent::*/preceding-sibling::t:title[not(@type='short')])]">
<xsl:apply-templates select="."/>
<xsl:if test="position()!=last()"> – </xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
<xsl:apply-templates select="$bibl//t:date"/>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$bibl-ref"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="t:title[not(ancestor::t:titleStmt)][not(@type='short')]" mode="#default inslib-dimensions inslib-placename sample-dimensions creta medcyprus-location medcyprus-dimensions">
<xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
<xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
<xsl:choose>
<xsl:when test="$parm-edn-structure=('inslib', 'sample') or $parm-leiden-style = 'medcyprus'">
<i><xsl:apply-templates/></i>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>