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

Last change on this file since 37085 was 37085, checked in by davidb, 16 months ago

Commented out code and OLD tempalte rules removed

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