source: gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document-iiif-manifest.xsl@ 37087

Last change on this file since 37087 was 37087, checked in by davidb, 17 months ago

Another round of tidy up

File size: 15.3 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:java="http://xml.apache.org/xslt/java"
5 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
6 xmlns:gslib="http://www.greenstone.org/skinning"
7 xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
8 extension-element-prefixes="java util"
9 exclude-result-prefixes="java util gsf">
10
11 <!--
12 Key goal: generate a IIIF v2 compliant manifest file in JSON format based on the document
13 -->
14
15 <!-- Similar in spirit to document.xsl (catering for 'simple' and complex document structures such as 'pages'),
16 but considerably tailored down to produce the raw IIIF-manifest JSON format:
17 (i) focus on just the (potientailly hierachically nested) pages
18 (ii) so a bit like ed=1, but implied rather than needing to be set
19 -->
20
21 <xsl:include href="layouts/header-core.xsl"/>
22
23 <xsl:include href="pages/document-shared.xsl" />
24 <xsl:include href="pages/document-core.xsl" />
25
26 <xsl:output method="html" version="1.0" encoding="utf-8"/>
27
28 <!--
29 <xsl:output method="text" version="1.0" encoding="utf-8" omit-xml-declaration="yes"/>
30 <xsl:strip-space elements="*"/>
31 -->
32
33 <xsl:variable name="iiifPresentationRootIdentifier">http-greenstone://<xsl:value-of select="$site_name"/>/<xsl:value-of select="$collNameChecked"/>/<xsl:value-of select="$docID"/></xsl:variable>
34
35 <!-- **** should be able to get rid of this, however at the moment it seems to be used in some supporting file !!!! -->
36
37 <xsl:variable name="bookswitch">mirador</xsl:variable>
38
39 <xsl:template match="/">
40 <html>
41 <body>
42 <xsl:apply-templates select="/page/pageResponse/document" />
43 </body>
44 </html>
45
46 </xsl:template>
47
48
49 <xsl:template name="iiif-other-content">
50 <xsl:param name="optSection"/>
51
52 <xsl:variable name="baseURL">https:<xsl:value-of select="/page/pageRequest/@baseURL"/></xsl:variable> <!-- **** had to hardwire https: -->
53 <!-- **** test for a gsf-option before include !!!! -->
54 "otherContent": [{
55 "@id": "<xsl:value-of select="$baseURL"/><xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collNameChecked"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/openannotation-list<xsl:value-of select="$optSection"/>.json",
56 "@type": "sc:AnnotationList"
57 }],
58 </xsl:template>
59
60
61 <!-- **** improve name !!!! -->
62
63 <xsl:template name="iiif-links">
64 <xsl:param name="identifier"/>
65 <xsl:param name="docType"/>
66
67 <xsl:variable name="iiifImageRootIdentifier">
68 <xsl:text>/gs-cantaloupe/iiif/2/</xsl:text><xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>
69 </xsl:variable>
70
71 <!-- page/pageRequest[@baseURL]="//intermuse.sowemustthink.space/greenstone3/ -->
72 <!-- page/pageRequest[@fullURL]="//intermuse.sowemustthink.space/greenstone3/library?a=d.... -->
73
74 <!-- ***** need to work out domain name to use from raw XML message, say processing something from the above -->
75
76 <xsl:variable name="document-location-origin">https://intermuse.sowemustthink.space</xsl:variable>
77
78 <xsl:variable name="section"><xsl:value-of select="position()" /></xsl:variable>
79 <xsl:variable name="optSection">
80 <xsl:choose>
81 <xsl:when test="$docType = 'simple'"></xsl:when><!-- i.e. empty -->
82 <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise>
83 </xsl:choose>
84 </xsl:variable>
85
86
87 <xsl:variable name="chosenTitle">
88 <xsl:choose>
89 <xsl:when test="$docType = 'simple'">
90 <xsl:call-template name="choose-title"/>
91 </xsl:when>
92 <xsl:otherwise>page <xsl:value-of select="$section"/></xsl:otherwise>
93 </xsl:choose>
94 </xsl:variable>
95
96 <!-- The following is useful for debugging, nested in 'pre' tags -->
97 <!--
98 docType = <xsl:value-of select="$docType"/>
99 docID = <xsl:value-of select="$docID"/>
100 position = <xsl:value-of select="position()" />
101
102 identifer = <xsl:value-of select="$identifier"/>
103 section = <xsl:value-of select="$section"/>
104 optSection = <xsl:value-of select="$optSection"/>
105
106 iiifPresRootIdentifier = <xsl:value-of select="$iiifPresentationRootIdentifier" />
107 iiifImageRootIdentifier = <xsl:value-of select="$iiifImageRootIdentifier" />
108 -->
109 <!-- an array entry in 'canvases': { @content, @id, @type, label, width, height, images[{}], thumbnail {@id,@type} } -->
110 <pre>
111 <!-- add a comma first, if it is not the first canvas element in the array -->
112 <xsl:if test="$section &gt; 1">
113 ,
114 </xsl:if>
115 {
116 "@context": "http://iiif.io/api/presentation/2/context.json",
117 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/canvas/<xsl:value-of select="$section"/>",
118 "@type": "sc:Canvas",
119 "label": "<xsl:value-of select="$chosenTitle"/>",
120 <xsl:call-template name="iiif-other-content">
121 <xsl:with-param name="optSection"><xsl:value-of select="$optSection"/></xsl:with-param>
122 </xsl:call-template>
123 &quot;width&quot;: <gsf:metadata name="ImageWidth"/>,
124 &quot;height&quot;: <gsf:metadata name="ImageHeight"/>,
125
126 "images": [{
127 "image": {
128 "@context": "http://iiif.io/api/image/2/context.json",
129 "@type": "oa:Annotation",
130 "motivation": "sc:painting",
131 "on": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/annotation/<xsl:value-of select="$section"/>",
132
133 "resource": {
134 "@id": "<xsl:value-of select="$document-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/full/0/default.jpg",
135 "@type": "dctypes:Image",
136 "format": "image/jpeg",
137 "width": <gsf:metadata name="ImageWidth"/>,
138 "hieght": <gsf:metadata name="ImageHeight"/>,
139 "service": {
140 "@context": "http://iiif.io/api/image/2/context.json",
141 "@id": "<xsl:value-of select="$document-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />",
142 "profile": "https://iiif.io/api/image/2/profiles/level2.json"
143 }
144 }
145 }
146 }],
147 "thumbnail": {
148 "@id": "<xsl:value-of select="$document-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/,150/0/default.jpg",
149 "@type": "dctypes:Image"
150 }
151 }
152 </pre>
153 <!-- Another field to consider in the above JSON is: -->
154 <!-- "format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed??? -->
155 </xsl:template>
156
157
158 <xsl:template name="wrappedSectionPost">
159
160 <!-- add in IIIF Server link for section image -->
161 <xsl:variable name="nodeID" select="@nodeID"/>
162 <xsl:call-template name="iiif-links">
163 <xsl:with-param name="identifier" select="$nodeID" />
164 <xsl:with-param name="docType" select="@docType" />
165 </xsl:call-template>
166 </xsl:template>
167
168 <xsl:template name="sectionImage">
169 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
170 </xsl:template>
171
172 <xsl:template name="sectionContent">
173 <xsl:call-template name="wrappedSectionPost"/>
174 </xsl:template>
175
176
177 <xsl:template name="documentPre">
178 <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
179
180 <xsl:variable name="chosenTitle">
181 <xsl:choose>
182 <xsl:when test="@docType='simple'">
183 <xsl:call-template name="choose-title"/>
184 </xsl:when>
185 <xsl:otherwise>
186 <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']" />
187 </xsl:otherwise>
188 </xsl:choose>
189 </xsl:variable>
190
191 <!-- start of iiif_manifest: -->
192 <pre>
193 {
194 "@context": "http://iiif.io/api/presentation/2/context.json",
195 "@type": "sc:Manifest",
196 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/manifest",
197 "label": "<xsl:value-of select="$chosenTitle"/>",
198 "attribution": "The Internet of Musical Events (InterMusE): Digital Scholarship, Community, and the Archiving of Performance",
199 "license": "https://**** To Be Determined ****",
200 "logo": "https://intermuse.datatodata.org/wp-content/uploads/sites/4/2021/03/cropped-cropped-cropped-1.png",
201 "metadata": [
202 { "label": "creator", "value": ["aaa1","aaa2"] },
203 { "label": "title", "value": ["chosen-title"] }
204 ],
205 <!-- trival IIIF sequences => has one IIIF canvas in it -->
206 "sequences": [{
207 "@context": "http://iiif.io/api/image/2/context.json",
208 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/sequence/normal",
209 "@type": "sc:Sequence",
210 "canvases": [
211 </pre>
212
213 </xsl:template>
214
215
216 <xsl:template name="documentContentSimpleIIIFImage">
217 <xsl:call-template name="iiif-links">
218 <xsl:with-param name="identifier" select="$docID" />
219 <xsl:with-param name="docType" select="@docType" />
220 </xsl:call-template>
221 </xsl:template>
222
223 <xsl:template name="documentContent">
224 <!-- The way document.xsl templates are structured, only get to here is if @docType = 'simple' -->
225 <!-- A 'paged' (or 'hierarical') document goes throgh 'wrappedContent' -->
226 <xsl:call-template name="documentPre"/>
227 <xsl:call-template name="documentContentSimpleIIIFImage"/>
228 <xsl:call-template name="documentPost"/>
229 </xsl:template>
230
231 <xsl:template name="documentPost">
232 <!-- end of iiif_manifest: -->
233 <!-- close of canvases, then close higher level blocks to complete the JSON file -->
234 <pre>
235 ]
236 }]
237 }
238 </pre>
239
240 </xsl:template>
241
242
243 <xsl:template name="wrappedDocumentTopLevel">
244
245 <!-- <xsl:call-template name="documentPre"/> -->
246 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
247 <!-- <xsl:call-template name="documentPost"/> -->
248 <!--
249 <xsl:call-template name="documentPostMirador3OLD"/>
250 -->
251
252 </xsl:template>
253
254
255 <xsl:template name="wrapDocumentNodes">
256
257 <xsl:choose>
258 <xsl:when test="../../document">
259 <xsl:call-template name="topLevelSectionContent"/>
260 </xsl:when>
261 <xsl:otherwise>
262 <xsl:call-template name="sectionContent"/>
263 </xsl:otherwise>
264 </xsl:choose>
265
266 <xsl:if test="documentNode">
267 <xsl:for-each select="documentNode">
268 <xsl:call-template name="wrapDocumentNodes"/>
269 </xsl:for-each>
270 </xsl:if>
271 </xsl:template>
272
273
274
275 <xsl:template name="wrappedSectionImage">
276 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
277 </xsl:template>
278
279 <!-- The default template for displaying the document node text -->
280 <!-- equivalent to gsf:text -->
281 <xsl:template name="documentNodeText">
282 <xsl:param name="force">0</xsl:param>
283 <!-- Hides the "This document has no text." message -->
284 <xsl:variable name="noText"><gsf:metadata name="NoText"/></xsl:variable>
285 <xsl:choose>
286 <xsl:when test="$force = '1' or not($noText = '1')">
287
288 <!-- Section text -->
289 <xsl:for-each select="nodeContent">
290 <xsl:call-template name="displayMarkedUpTextAndAnnotations"/>
291 </xsl:for-each>
292 </xsl:when>
293 <xsl:when test="$noText = '1' and not(metadataList/metadata[@name='ImageType'])">
294 <gsf:link type="source"><gsf:metadata name="Source"/></gsf:link>
295 </xsl:when>
296 </xsl:choose>
297 <xsl:text> </xsl:text>
298 </xsl:template>
299
300
301
302
303
304 <xsl:template match="/page/pageResponse/document">
305 <!-- display the document -->
306 <xsl:choose>
307 <xsl:when test="@docType='simple'">
308 <xsl:call-template name="documentHeading"/><br/>
309 <xsl:call-template name="documentContentTopLevel"/>
310 </xsl:when>
311 <xsl:otherwise> <!-- display the standard greenstone document -->
312 <xsl:call-template name="wrappedDocumentTopLevel"/>
313 </xsl:otherwise>
314 </xsl:choose>
315 </xsl:template>
316
317
318 <!-- **** SIMPLIFY !!!! -->
319
320 <xsl:template name="wrappedDocument">
321 <xsl:choose>
322 <!-- NOTE: alb = ajax load bypass -->
323 <!--
324 If we have asked for expanded document, then do this.
325 OR If the docType is hierarchy and we want to bypass the ajax load then do this
326 OR If the docType is hierarchy and we have asked for the top level document then do this
327 -->
328 <xsl:when test="/page/pageRequest/paramList/param[@name = 'ed']/@value = '1' or (/page/pageResponse/document/@docType = 'hierarchy' and (/page/pageRequest/paramList/param[@name = 'alb']/@value = '1' or (string-length(/page/pageRequest/paramList/param[@name = 'd']/@value) > 0 and not(util:contains(/page/pageResponse/document/@selectedNode, '.')))))">
329 <div id="gs-document">
330 <xsl:call-template name="documentPre"/>
331 <div id="gs-document-text" class="documenttext" collection="{/page/pageResponse/collection/@name}"><!-- *** -->
332 <xsl:for-each select="documentNode">
333 <xsl:call-template name="wrapDocumentNodes"/>
334 </xsl:for-each>
335 </div>
336 <xsl:call-template name="documentPost"/>
337 </div>
338 </xsl:when>
339 <xsl:when test="/page/pageResponse/document/@docType = 'paged' or /page/pageResponse/document/@docType = 'pagedhierarchy'">
340 <div id="gs-document">
341 <div id="tocLoadingImage" style="text-align:center;">
342 <img src="{util:getInterfaceText($interface_name, /page/@lang, 'loading_image')}"/><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.loading')"/><xsl:text>...</xsl:text>
343 </div>
344 </div>
345 <script type="text/javascript">
346 <xsl:text disable-output-escaping="yes">
347 $(window).on("load", function()
348 {
349 var sectionID = gs.cgiParams.d;
350 var callbackFunction = null;
351 if(sectionID.indexOf(".") != -1)
352 {
353 callbackFunction = function()
354 {
355 focusSection(sectionID);
356 };
357 }
358 else {
359 callbackFunction = function()
360 {
361
362 expandAndExecute(sectionID+".1", null, null, null);
363 };
364 }
365 var docID = sectionID.replace(/([^.]*)\..*/, "$1");
366 var url = gs.xsltParams.library_name + "?a=d&amp;c=" + gs.cgiParams.c + "&amp;excerptid=gs-document&amp;dt=hierarchy&amp;d=" + docID;
367 if(gs.cgiParams.p_s) {
368 url += "&amp;p.s="+gs.cgiParams.p_s;
369 }
370 loadTopLevelPage(callbackFunction, url);
371 });
372 </xsl:text>
373 </script>
374 </xsl:when>
375 <xsl:otherwise>
376 <div id="gs-document">
377 <div id="tocLoadingImage" style="text-align:center;">
378 <img src="{util:getInterfaceText($interface_name, /page/@lang, 'loading_image')}"/><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'doc.loading')"/><xsl:text>...</xsl:text>
379 </div>
380 </div>
381 <script type="text/javascript">
382 <xsl:text disable-output-escaping="yes">
383 $(window).on("load", function()
384 {
385 loadTopLevelPage(function()
386 {
387 //Don't focus the section until the table of contents is loaded
388 var tocCheck = function()
389 {
390 if(gs.variables.tocLoaded)
391 {
392 focusSection("</xsl:text><xsl:value-of select="/page/pageResponse/document/@selectedNode"/><xsl:text disable-output-escaping="yes">");
393 }
394 else
395 {
396 setTimeout(tocCheck, 500);
397 }
398 }
399 tocCheck();
400 });
401 });
402 </xsl:text>
403 </script>
404 </xsl:otherwise>
405 </xsl:choose>
406
407 <div class="clear"><xsl:text> </xsl:text></div>
408 </xsl:template>
409
410
411
412
413</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.