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

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

After a further round of culling

File size: 18.2 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 <xsl:template name="iiif-links">
62 <xsl:param name="identifier"/>
63 <xsl:param name="docType"/>
64
65 <xsl:variable name="iiifImageRootIdentifier">
66 <xsl:text>/gs-cantaloupe/iiif/2/</xsl:text><xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>
67 </xsl:variable>
68
69 <!-- page/pageRequest[@baseURL]="//intermuse.sowemustthink.space/greenstone3/ -->
70 <!-- page/pageRequest[@fullURL]="//intermuse.sowemustthink.space/greenstone3/library?a=d.... -->
71
72 <!-- ***** need to work out from raw XML message, say processing something from the above -->
73
74 <xsl:variable name="document-location-origin">https://intermuse.sowemustthink.space</xsl:variable>
75
76 <xsl:variable name="section"><xsl:value-of select="position()" /></xsl:variable>
77 <xsl:variable name="optSection">
78 <xsl:choose>
79 <xsl:when test="$docType = 'simple'"></xsl:when><!-- i.e. empty -->
80 <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise>
81 </xsl:choose>
82 </xsl:variable>
83
84
85 <xsl:variable name="chosenTitle">
86 <xsl:choose>
87 <xsl:when test="$docType = 'simple'">
88 <xsl:call-template name="choose-title"/>
89 </xsl:when>
90 <xsl:otherwise>page <xsl:value-of select="$section"/></xsl:otherwise>
91 </xsl:choose>
92 </xsl:variable>
93
94 <!-- The following is useful for debugging, nested in 'pre' tags -->
95 <!--
96 docType = <xsl:value-of select="$docType"/>
97 docID = <xsl:value-of select="$docID"/>
98 position = <xsl:value-of select="position()" />
99
100 identifer = <xsl:value-of select="$identifier"/>
101 section = <xsl:value-of select="$section"/>
102 optSection = <xsl:value-of select="$optSection"/>
103
104 iiifPresRootIdentifier = <xsl:value-of select="$iiifPresentationRootIdentifier" />
105 iiifImageRootIdentifier = <xsl:value-of select="$iiifImageRootIdentifier" />
106 -->
107 <!-- an array entry in 'canvases': { @content, @id, @type, label, width, height, images[{}], thumbnail {@id,@type} } -->
108 <pre>
109 <!-- add a comma first, if it is not the first canvas element in the array -->
110 <xsl:if test="$section &gt; 1">
111 ,
112 </xsl:if>
113 {
114 "@context": "http://iiif.io/api/presentation/2/context.json",
115 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/canvas/<xsl:value-of select="$section"/>",
116 "@type": "sc:Canvas",
117 "label": "<xsl:value-of select="$chosenTitle"/>",
118 <xsl:call-template name="iiif-other-content">
119 <xsl:with-param name="optSection"><xsl:value-of select="$optSection"/></xsl:with-param>
120 </xsl:call-template>
121 &quot;width&quot;: <gsf:metadata name="ImageWidth"/>,
122 &quot;height&quot;: <gsf:metadata name="ImageHeight"/>,
123
124 "images": [{
125 "image": {
126 "@context": "http://iiif.io/api/image/2/context.json",
127 "@type": "oa:Annotation",
128 "motivation": "sc:painting",
129 "on": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/annotation/<xsl:value-of select="$section"/>",
130
131 "resource": {
132 "@id": "<xsl:value-of select="$document-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/full/0/default.jpg",
133 "@type": "dctypes:Image",
134 "format": "image/jpeg",
135 "width": <gsf:metadata name="ImageWidth"/>,
136 "hieght": <gsf:metadata name="ImageHeight"/>,
137 "service": {
138 "@context": "http://iiif.io/api/image/2/context.json",
139 "@id": "<xsl:value-of select="$document-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />",
140 "profile": "https://iiif.io/api/image/2/profiles/level2.json"
141 }
142 }
143 }
144 }],
145 "thumbnail": {
146 "@id": "<xsl:value-of select="$document-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/,150/0/default.jpg",
147 "@type": "dctypes:Image"
148 }
149 }
150 </pre>
151 <!-- Another field to consider in the above JSON is: -->
152 <!-- "format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed??? -->
153 </xsl:template>
154
155
156 <xsl:template name="wrappedSectionPost">
157
158 <!-- **** improve name !!!! -->
159 <!-- add in IIIF Server link for section image -->
160 <xsl:variable name="nodeID" select="@nodeID"/>
161 <xsl:call-template name="iiif-links">
162 <xsl:with-param name="identifier" select="$nodeID" />
163 <xsl:with-param name="docType" select="@docType" />
164 </xsl:call-template>
165 </xsl:template>
166
167 <xsl:template name="sectionImage">
168 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
169 </xsl:template>
170
171 <xsl:template name="sectionContent">
172 <xsl:call-template name="wrappedSectionPost"/>
173 </xsl:template>
174
175
176 <xsl:template name="documentPre">
177 <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
178
179 <xsl:variable name="chosenTitle">
180 <xsl:choose>
181 <xsl:when test="@docType='simple'">
182 <xsl:call-template name="choose-title"/>
183 </xsl:when>
184 <xsl:otherwise>
185 <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']" />
186 </xsl:otherwise>
187 </xsl:choose>
188 </xsl:variable>
189
190 <!-- start of iiif_manifest: -->
191 <pre>
192 {
193 "@context": "http://iiif.io/api/presentation/2/context.json",
194 "@type": "sc:Manifest",
195 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/manifest",
196 "label": "<xsl:value-of select="$chosenTitle"/>",
197 "attribution": "The Internet of Musical Events (InterMusE): Digital Scholarship, Community, and the Archiving of Performance",
198 "license": "https://**** To Be Determined ****",
199 "logo": "https://intermuse.datatodata.org/wp-content/uploads/sites/4/2021/03/cropped-cropped-cropped-1.png",
200 "metadata": [
201 { "label": "creator", "value": ["aaa1","aaa2"] },
202 { "label": "title", "value": ["chosen-title"] }
203 ],
204 <!-- trival IIIF sequences => has one IIIF canvas in it -->
205 "sequences": [{
206 "@context": "http://iiif.io/api/image/2/context.json",
207 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/sequence/normal",
208 "@type": "sc:Sequence",
209 "canvases": [
210 </pre>
211
212 </xsl:template>
213
214
215 <xsl:template name="documentContentSimpleIIIFImage">
216 <xsl:call-template name="iiif-links">
217 <xsl:with-param name="identifier" select="$docID" />
218 <xsl:with-param name="docType" select="@docType" />
219 </xsl:call-template>
220 </xsl:template>
221
222 <xsl:template name="documentContent">
223 <!-- The way document.xsl templates are structured, only get to here is if @docType = 'simple' -->
224 <!-- A 'paged' (or 'hierarical') document goes throgh 'wrappedContent' -->
225 <xsl:call-template name="documentPre"/>
226 <xsl:call-template name="documentContentSimpleIIIFImage"/>
227 <xsl:call-template name="documentPost"/>
228 <!--
229 <xsl:call-template name="documentPostMirador3OLD"/>
230 -->
231 </xsl:template>
232
233 <xsl:template name="documentPost">
234 <!-- end of iiif_manifest: -->
235 <!-- close of canvases, then close higher level blocks to complete the JSON file -->
236 <pre>
237 ]
238 }]
239 }
240 </pre>
241
242 </xsl:template>
243
244
245 <xsl:template name="documentPostMirador3OLD">
246
247 <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->
248 <div style="position: relative; width: 100%; height: 800px;">
249 <div id="mirador3-viewer"> <xsl:comment>filler</xsl:comment></div>
250 </div>
251
252 </xsl:template>
253
254 <xsl:template name="wrappedDocumentTopLevel">
255
256 <!-- <xsl:call-template name="documentPre"/> -->
257 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
258 <!-- <xsl:call-template name="documentPost"/> -->
259 <!--
260 <xsl:call-template name="documentPostMirador3OLD"/>
261 -->
262
263 </xsl:template>
264
265
266 <!-- **** see about eliminating the following => shouldn't be needed! !!!! -->
267 <!-- content of a simple document. Will not be used for editing mode -->
268 <xsl:template name="documentPostInProgressOLD">
269
270
271 <gsf:script src="https://unpkg.com/mirador@latest/dist/mirador.min.js"/>
272
273
274 <!-- By default uses Roboto font. Be sure to load this or change the font -->
275 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
276 <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->
277
278 <div style="position: relative; width: 100%; height: 800px;">
279 <div id="my-mirador"> <xsl:comment>filler</xsl:comment></div>
280 </div>
281
282 <gsf:script>
283
284var mirador = Mirador.viewer({
285 "id": "my-mirador",
286 "manifests": {
287 "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {
288 "provider": "IntermusE"
289 }
290 },
291 "window" : { "panels" : { "annotations": true, "attribution": false } },
292 "annotations": {
293 "htmlSanitizationRuleSet": 'iiif', // See src/lib/htmlRules.js for acceptable values
294 "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'],
295 },
296 "windows": [
297 {
298 "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",
299 "canvasIndex": 1,
300 "thumbnailNavigationPosition": 'far-bottom'
301 }
302 ]
303});
304 </gsf:script>
305
306
307 </xsl:template>
308
309
310
311 <xsl:template name="wrapDocumentNodes">
312
313 <xsl:choose>
314 <xsl:when test="../../document">
315 <xsl:call-template name="topLevelSectionContent"/>
316 </xsl:when>
317 <xsl:otherwise>
318 <xsl:call-template name="sectionContent"/>
319 </xsl:otherwise>
320 </xsl:choose>
321
322 <xsl:if test="documentNode">
323 <xsl:for-each select="documentNode">
324 <xsl:call-template name="wrapDocumentNodes"/>
325 </xsl:for-each>
326 </xsl:if>
327 </xsl:template>
328
329
330
331 <xsl:template name="wrappedSectionImage">
332 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
333 </xsl:template>
334
335 <xsl:template name="wrappedSectionImageOLD">
336 <xsl:variable name="screenImageWidth"><gsf:metadata name="ScreenWidth"/></xsl:variable>
337 <xsl:variable name="screenImageHeight"><gsf:metadata name="ScreenHeight"/></xsl:variable>
338 <xsl:variable name="imageWidth"><gsf:metadata name="ImageWidth"/></xsl:variable>
339 <xsl:variable name="imageHeight"><gsf:metadata name="ImageHeight"/></xsl:variable>
340 <xsl:variable name="docNodeID"><xsl:value-of select="@nodeID"/></xsl:variable> <!-- used to make each 'tidyDiv' unique -->
341
342 <gsf:div id="image{@nodeID}">
343 <xsl:attribute name="style">
344 <xsl:choose>
345 <xsl:when test="/page/pageRequest/paramList/param[@name = 'view']/@value = 'text'">
346 <xsl:text>display:none;</xsl:text>
347 </xsl:when>
348 <xsl:otherwise>
349 <xsl:text>display:block;</xsl:text>
350 </xsl:otherwise>
351 </xsl:choose>
352 </xsl:attribute>
353 <xsl:call-template name="sectionImage"/><xsl:text> </xsl:text>
354 </gsf:div>
355
356
357 </xsl:template>
358
359 <!-- The default template for displaying the document node text -->
360 <!-- equivalent to gsf:text -->
361 <xsl:template name="documentNodeText">
362 <xsl:param name="force">0</xsl:param>
363 <!-- Hides the "This document has no text." message -->
364 <xsl:variable name="noText"><gsf:metadata name="NoText"/></xsl:variable>
365 <xsl:choose>
366 <xsl:when test="$force = '1' or not($noText = '1')">
367
368 <!-- Section text -->
369 <xsl:for-each select="nodeContent">
370 <xsl:call-template name="displayMarkedUpTextAndAnnotations"/>
371 </xsl:for-each>
372 </xsl:when>
373 <xsl:when test="$noText = '1' and not(metadataList/metadata[@name='ImageType'])">
374 <gsf:link type="source"><gsf:metadata name="Source"/></gsf:link>
375 </xsl:when>
376 </xsl:choose>
377 <xsl:text> </xsl:text>
378 </xsl:template>
379
380
381
382
383
384 <xsl:template match="/page/pageResponse/document">
385 <!-- display the document -->
386 <xsl:choose>
387 <xsl:when test="@docType='simple'">
388 <xsl:call-template name="documentHeading"/><br/>
389 <xsl:call-template name="documentContentTopLevel"/>
390 </xsl:when>
391 <xsl:otherwise> <!-- display the standard greenstone document -->
392 <xsl:call-template name="wrappedDocumentTopLevel"/>
393 </xsl:otherwise>
394 </xsl:choose>
395 </xsl:template>
396
397
398 <!-- **** SIMPLIFY !!!! -->
399
400 <xsl:template name="wrappedDocument">
401 <xsl:choose>
402 <!-- NOTE: alb = ajax load bypass -->
403 <!--
404 If we have asked for expanded document, then do this.
405 OR If the docType is hierarchy and we want to bypass the ajax load then do this
406 OR If the docType is hierarchy and we have asked for the top level document then do this
407 -->
408 <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, '.')))))">
409 <div id="gs-document">
410 <xsl:call-template name="documentPre"/>
411 <div id="gs-document-text" class="documenttext" collection="{/page/pageResponse/collection/@name}"><!-- *** -->
412 <xsl:for-each select="documentNode">
413 <xsl:call-template name="wrapDocumentNodes"/>
414 </xsl:for-each>
415 </div>
416 <xsl:call-template name="documentPost"/>
417 </div>
418 </xsl:when>
419 <xsl:when test="/page/pageResponse/document/@docType = 'paged' or /page/pageResponse/document/@docType = 'pagedhierarchy'">
420 <div id="gs-document">
421 <div id="tocLoadingImage" style="text-align:center;">
422 <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>
423 </div>
424 </div>
425 <script type="text/javascript">
426 <xsl:text disable-output-escaping="yes">
427 $(window).on("load", function()
428 {
429 var sectionID = gs.cgiParams.d;
430 var callbackFunction = null;
431 if(sectionID.indexOf(".") != -1)
432 {
433 callbackFunction = function()
434 {
435 focusSection(sectionID);
436 };
437 }
438 else {
439 callbackFunction = function()
440 {
441
442 expandAndExecute(sectionID+".1", null, null, null);
443 };
444 }
445 var docID = sectionID.replace(/([^.]*)\..*/, "$1");
446 var url = gs.xsltParams.library_name + "?a=d&amp;c=" + gs.cgiParams.c + "&amp;excerptid=gs-document&amp;dt=hierarchy&amp;d=" + docID;
447 if(gs.cgiParams.p_s) {
448 url += "&amp;p.s="+gs.cgiParams.p_s;
449 }
450 loadTopLevelPage(callbackFunction, url);
451 });
452 </xsl:text>
453 </script>
454 </xsl:when>
455 <xsl:otherwise>
456 <div id="gs-document">
457 <div id="tocLoadingImage" style="text-align:center;">
458 <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>
459 </div>
460 </div>
461 <script type="text/javascript">
462 <xsl:text disable-output-escaping="yes">
463 $(window).on("load", function()
464 {
465 loadTopLevelPage(function()
466 {
467 //Don't focus the section until the table of contents is loaded
468 var tocCheck = function()
469 {
470 if(gs.variables.tocLoaded)
471 {
472 focusSection("</xsl:text><xsl:value-of select="/page/pageResponse/document/@selectedNode"/><xsl:text disable-output-escaping="yes">");
473 }
474 else
475 {
476 setTimeout(tocCheck, 500);
477 }
478 }
479 tocCheck();
480 });
481 });
482 </xsl:text>
483 </script>
484 </xsl:otherwise>
485 </xsl:choose>
486
487 <div class="clear"><xsl:text> </xsl:text></div>
488 </xsl:template>
489
490
491
492
493</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.