source: main/trunk/greenstone3/web/interfaces/default/transform/pages/document-iiif-manifest.xsl

Last change on this file was 38489, checked in by davidb, 4 months ago

Closing up whitespace to resolve an HTML syntax issue to arose on a fresh install of the Intermuse DL

File size: 13.6 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-vars.xsl"/>
22
23 <!--
24 <xsl:include href="pages/document-shared.xsl" />
25 -->
26
27 <xsl:include href="pages/document-vars.xsl" />
28
29 <!-- Additional changes needed to GS3 Java runtine for the following output tag to operate correctly -->
30 <!-- Testing with o=xsl and the debug XML+XSL pair of files generated (when an error was encountred)
31 showed that the Greenstone3 runtime does not currently honour the output tag, in fact gslib.xsl
32 entries seem to turn up later on, and as this includes html-output.xsl, then a later xsl:output
33 tag is generated. The problems runner deeper than this however, with the XSLT output generated
34 having a DTD. Looks like gsdl3/TransformingReceptionist.java is geared to always generating
35 XML output of some form of other (e.g. RSS XML output). Generating raw text just doesn't
36 seem to get through. So to make progress have introduced CGI argument 'excerptid-text'
37 as a way of getting to the text that is generated within, say, a <pre> elemlent with an id attribute -->
38 <!--
39 <xsl:output method="text" version="1.0" encoding="utf-8" omit-xml-declaration="yes"/>
40 <xsl:strip-space elements="*"/>
41 -->
42
43 <!-- page/pageRequest[@baseURL]="//intermuse.sowemustthink.space/greenstone3/ -->
44 <!-- page/pageRequest[@fullURL]="//intermuse.sowemustthink.space/greenstone3/library?a=d.... -->
45 <!-- <xsl:variable name="window-location-origin">https://intermuse.sowemustthink.space</xsl:variable> -->
46 <xsl:variable name="window-location-origin">http://localhost:8383</xsl:variable>
47
48 <!-- optional cgi-params for links to document pages -->
49 <xsl:variable name="opt-doc-link-args"></xsl:variable>
50 <xsl:variable name="bookswitch"></xsl:variable>
51
52 <xsl:variable name="iiifPresentationRootIdentifier">http://ld.greenstone.org/<xsl:value-of select="$site_name"/>/<xsl:value-of select="$collNameChecked"/>/<xsl:value-of select="$docID"/></xsl:variable>
53
54 <xsl:template match="/">
55 <html>
56 <body>
57 <pre id="iiif-manifest">
58 <xsl:apply-templates select="/page/pageResponse/document" />
59 </pre>
60 </body>
61 </html>
62 </xsl:template>
63
64 <xsl:template match="/page/pageResponse/document">
65 <!-- display the document -->
66 <xsl:choose>
67 <xsl:when test="@docType='simple'">
68 <xsl:call-template name="documentContent"/>
69 </xsl:when>
70 <xsl:otherwise> <!-- kick off the recursive call for a more complex structured document-->
71 <xsl:call-template name="wrappedDocumentTopLevel"/>
72 </xsl:otherwise>
73 </xsl:choose>
74 </xsl:template>
75
76
77 <xsl:template name="wrappedDocumentTopLevel">
78 <!-- <xsl:call-template name="documentPre"/> -->
79 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
80 <!-- <xsl:call-template name="documentPost"/> -->
81 </xsl:template>
82
83 <xsl:template name="wrappedDocument">
84 <xsl:call-template name="documentPre"/>
85 <xsl:for-each select="documentNode">
86 <xsl:call-template name="wrapDocumentNodes"/>
87 </xsl:for-each>
88 <xsl:call-template name="documentPost"/>
89 </xsl:template>
90
91
92 <xsl:template name="iiif-other-content">
93 <xsl:param name="optSection"/>
94 <xsl:variable name="baseURL">http:<xsl:value-of select="/page/pageRequest/@baseURL"/></xsl:variable> <!-- **** currently need to hardwire as http: or https: -->
95 <xsl:variable name="gsfOptionIncludeFileAssocOpenAnnotations">
96 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeFileAssocOpenAnnotations']/@value"></xsl:value-of>
97 </xsl:variable>
98 <xsl:variable name="cgiParamIncludeFileAssocOpenAnnotations">
99 <xsl:value-of select="/page/pageRequest/paramList/param[@name='includeFileAssocOpenAnnotations']/@value"></xsl:value-of>
100 </xsl:variable>
101
102 <xsl:if test="$gsfOptionIncludeFileAssocOpenAnnotations='true' or $cgiParamIncludeFileAssocOpenAnnotations='true'">
103 "otherContent": [{
104 "@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",
105 "@type": "sc:AnnotationList"
106 }],
107 </xsl:if>
108 </xsl:template>
109
110
111 <xsl:template name="iiif-canvas-image">
112 <xsl:param name="identifier"/>
113 <xsl:param name="docType"/>
114 <!-- -->
115 <xsl:variable name="iiifImageRootIdentifier">
116 <xsl:text>/gs-cantaloupe/iiif/2/</xsl:text><xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>
117 </xsl:variable>
118
119 <xsl:variable name="section"><xsl:value-of select="position()" /></xsl:variable>
120 <xsl:variable name="optSection">
121 <xsl:choose>
122 <xsl:when test="$docType = 'simple'"></xsl:when><!-- i.e. empty -->
123 <xsl:otherwise><xsl:value-of select="position()" /></xsl:otherwise>
124 </xsl:choose>
125 </xsl:variable>
126 <xsl:variable name="chosenTitle">
127 <xsl:choose>
128 <xsl:when test="$docType = 'simple'">
129 <xsl:call-template name="choose-title"/>
130 </xsl:when>
131 <xsl:otherwise>page <xsl:value-of select="$section"/></xsl:otherwise>
132 </xsl:choose>
133 </xsl:variable>
134 <!-- The following is useful for debugging, nested in 'pre' tags -->
135 <!--
136 docType = <xsl:value-of select="$docType"/>
137 docID = <xsl:value-of select="$docID"/>
138 position = <xsl:value-of select="position()" />
139
140 identifer = <xsl:value-of select="$identifier"/>
141 section = <xsl:value-of select="$section"/>
142 optSection = <xsl:value-of select="$optSection"/>
143
144 iiifPresRootIdentifier = <xsl:value-of select="$iiifPresentationRootIdentifier" />
145 iiifImageRootIdentifier = <xsl:value-of select="$iiifImageRootIdentifier" />
146 -->
147 <!-- an array entry in 'canvases': { @content, @id, @type, label, width, height, images[{}], thumbnail {@id,@type} } -->
148 <!-- add a comma first, if it is not the first canvas element in the array -->
149 <xsl:if test="$section &gt; 1">
150 ,
151 </xsl:if>
152 {
153 "@context": "http://iiif.io/api/presentation/2/context.json",
154 "@id" : "<xsl:value-of select="$iiifPresentationRootIdentifier" />/canvas/<xsl:value-of select="$section"/>",
155 "@type" : "sc:Canvas",
156 "label" : "<xsl:value-of select="$chosenTitle"/>",
157 <xsl:call-template name="iiif-other-content">
158 <xsl:with-param name="optSection"><xsl:value-of select="$optSection"/></xsl:with-param>
159 </xsl:call-template>
160 "width" : <gsf:metadata name="ImageWidth"/>,
161 "height" : <gsf:metadata name="ImageHeight"/>,
162 "images": [{
163 "@context": "http://iiif.io/api/image/2/context.json",
164 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/annotation/<xsl:value-of select="$section"/>",
165 "@type": "oa:Annotation",
166 "motivation": "sc:painting",
167 "on": "<xsl:value-of select="$iiifPresentationRootIdentifier" />/canvas",
168 "resource": {
169 "@id": "<xsl:value-of select="$window-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/full/0/default.jpg",
170 "@type": "dctypes:Image",
171 "format": "image/jpeg",
172 "width": <gsf:metadata name="ImageWidth"/>,
173 "hieght": <gsf:metadata name="ImageHeight"/>,
174 "service": {
175 "@context": "http://iiif.io/api/image/2/context.json",
176 "@id": "<xsl:value-of select="$window-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />",
177 "profile": "https://iiif.io/api/image/2/profiles/level2.json"
178 }
179 }
180 }],
181 "thumbnail": {
182 "@id": "<xsl:value-of select="$window-location-origin" /><xsl:value-of select="$iiifImageRootIdentifier" />/full/,150/0/default.jpg",
183 "@type": "dctypes:Image"
184 }
185 }
186 <!-- Another field to consider in the above JSON is: -->
187 <!-- "format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed??? -->
188 </xsl:template>
189
190
191 <xsl:template name="wrappedSectionPost">
192
193 <!-- add in IIIF Server link for section image -->
194 <xsl:variable name="nodeID" select="@nodeID"/>
195 <xsl:call-template name="iiif-canvas-image">
196 <xsl:with-param name="identifier" select="$nodeID" />
197 <xsl:with-param name="docType" select="@docType" />
198 </xsl:call-template>
199 </xsl:template>
200
201 <xsl:template name="sectionImage">
202 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
203 </xsl:template>
204
205 <xsl:template name="sectionContent">
206 <xsl:call-template name="wrappedSectionPost"/>
207 </xsl:template>
208
209
210 <xsl:template name="documentPre">
211 <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
212
213 <xsl:variable name="toplevelChosenTitle">
214 <xsl:choose>
215 <xsl:when test="@docType='simple'"><xsl:call-template name="choose-title"/></xsl:when>
216 <xsl:otherwise><xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']" /></xsl:otherwise>
217 </xsl:choose>
218 </xsl:variable>
219
220 <xsl:variable name="toplevelSASShortID">
221 <xsl:choose>
222 <xsl:when test="@docType='simple'">
223 <gsf:metadata name="SASShortID" />
224 </xsl:when>
225 <xsl:otherwise>
226 <xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='SASShortID']" />
227 </xsl:otherwise>
228 </xsl:choose>
229 </xsl:variable>
230
231
232 <!-- start of iiif_manifest: -->
233 {
234 "@context": "http://iiif.io/api/presentation/2/context.json",
235 "@type": "sc:Manifest",
236 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/manifest",
237 "label": "<xsl:value-of select="$toplevelChosenTitle"/>",
238 "attribution": "The Internet of Musical Events (InterMusE): Digital Scholarship, Community, and the Archiving of Performance",
239 "license": "https://**** To Be Determined ****",
240 "logo": "https://intermuse.datatodata.org/wp-content/uploads/sites/4/2021/03/cropped-cropped-cropped-1.png",
241 "metadata": [
242 { "label": "creator", "value": ["aaa1","aaa2"] },
243 { "label": "title", "value": ["chosen-title"] }
244 ],
245
246 "service": {
247 "profile": "http://iiif.io/api/search/0/search",
248 "@id": "http://localhost:8383/simpleAnnotationStore/search-api/<xsl:value-of select="$toplevelSASShortID"/>/search",
249 "@context": "http://iiif.io/api/search/0/context.json"
250 },
251
252 <!-- trival IIIF sequences => has one IIIF canvas in it -->
253 "sequences": [{
254 "@context": "http://iiif.io/api/image/2/context.json",
255 "@id": "<xsl:value-of select="$iiifPresentationRootIdentifier"/>/sequence/normal",
256 "@type": "sc:Sequence",
257 "canvases": [
258 </xsl:template>
259
260
261 <xsl:template name="documentContentSimpleIIIFImage">
262 <xsl:call-template name="iiif-canvas-image">
263 <xsl:with-param name="identifier" select="$docID" />
264 <xsl:with-param name="docType" select="@docType" />
265 </xsl:call-template>
266 </xsl:template>
267
268 <xsl:template name="documentContent">
269 <!-- The way document.xsl templates are structured, only get to here is if @docType = 'simple' -->
270 <!-- A 'paged' (or 'hierarical') document goes throgh 'wrappedContent' -->
271 <xsl:call-template name="documentPre"/>
272 <xsl:call-template name="documentContentSimpleIIIFImage"/>
273 <xsl:call-template name="documentPost"/>
274 </xsl:template>
275
276
277 <xsl:template name="wrapDocumentNodes">
278
279 <xsl:if test="@nodeType = 'leaf'">
280 <!-- for iiif-manifest JSON, put out a flat-list of images => only interested in leaf nodes -->
281 <xsl:call-template name="sectionContent"/>
282 </xsl:if>
283
284 <xsl:if test="documentNode">
285 <xsl:for-each select="documentNode">
286 <xsl:call-template name="wrapDocumentNodes"/>
287 </xsl:for-each>
288 </xsl:if>
289 </xsl:template>
290
291 <xsl:template name="wrappedSectionImage">
292 <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
293 </xsl:template>
294
295
296
297 <xsl:template name="documentPost">
298 <!-- end of iiif_manifest: -->
299 <!-- close of canvases, then close higher level blocks to complete the JSON file -->
300 ]
301 }]
302 }
303 </xsl:template>
304
305
306</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.