Index: /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document-iiif-manifest.xsl
===================================================================
--- /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document-iiif-manifest.xsl	(revision 37088)
+++ /gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document-iiif-manifest.xsl	(revision 37089)
@@ -19,9 +19,12 @@
   -->
 
+  <!-- **** this only defines xsl-variables => change filename? -->
   <xsl:include href="layouts/header-core.xsl"/>
 
   <xsl:include href="pages/document-shared.xsl" />
+  <!-- **** this only defines xsl-variables => change filename? -->  
   <xsl:include href="pages/document-core.xsl" />
 
+  
   <xsl:output method="html" version="1.0" encoding="utf-8"/>
   
@@ -30,15 +33,14 @@
   <xsl:strip-space elements="*"/>
   -->
-    
+
+  
   <xsl:variable name="iiifPresentationRootIdentifier">http-greenstone://<xsl:value-of select="$site_name"/>/<xsl:value-of select="$collNameChecked"/>/<xsl:value-of select="$docID"/></xsl:variable>
 
-  <!-- **** should be able to get rid of this, however at the moment it seems to be used in some supporting file !!!! -->
-  
-  <xsl:variable name="bookswitch">mirador</xsl:variable>
-    
   <xsl:template match="/">
-    <html>
-      <body>
-	<xsl:apply-templates select="/page/pageResponse/document" />
+      <html>
+	<body>
+	  <pre>
+	  <xsl:apply-templates select="/page/pageResponse/document" />
+	</pre>
       </body>
     </html>
@@ -46,5 +48,37 @@
   </xsl:template>
 
-
+  <xsl:template match="/page/pageResponse/document">
+    <!-- display the document -->
+    <xsl:choose>
+      <xsl:when test="@docType='simple'">
+	<xsl:call-template name="documentContent"/>
+      </xsl:when>	
+      <xsl:otherwise> <!-- kick off the recursive call for a more complex structured document-->
+	<xsl:call-template name="wrappedDocumentTopLevel"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  
+  <xsl:template name="wrappedDocumentTopLevel">
+
+    <!-- <xsl:call-template name="documentPre"/> -->
+    <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
+    <!-- <xsl:call-template name="documentPost"/> -->
+
+  </xsl:template>
+
+
+  <xsl:template name="wrappedDocument">
+
+    <xsl:call-template name="documentPre"/>
+      <xsl:for-each select="documentNode">
+	<xsl:call-template name="wrapDocumentNodes"/>
+      </xsl:for-each>
+    <xsl:call-template name="documentPost"/>					
+    
+  </xsl:template>	
+  
+  
   <xsl:template name="iiif-other-content">
     <xsl:param name="optSection"/>
@@ -59,7 +93,5 @@
   
 
-  <!-- **** improve name !!!! -->
-  
-  <xsl:template name="iiif-links">
+  <xsl:template name="iiif-canvas-image">
     <xsl:param name="identifier"/>
     <xsl:param name="docType"/>
@@ -108,5 +140,4 @@
     -->
     <!-- an array entry in 'canvases': { @content, @id, @type, label, width, height, images[{}], thumbnail {@id,@type} } -->
-    <pre>
       <!-- add a comma first, if it is not the first canvas element in the array -->
       <xsl:if test="$section &gt; 1">
@@ -150,5 +181,4 @@
 	      }
             }      
-    </pre>
     <!-- Another field to consider in the above JSON is: -->
     <!--   "format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed??? -->
@@ -160,5 +190,5 @@
     <!-- add in IIIF Server link for section image -->
     <xsl:variable name="nodeID" select="@nodeID"/>
-    <xsl:call-template name="iiif-links">
+    <xsl:call-template name="iiif-canvas-image">
       <xsl:with-param name="identifier" select="$nodeID" />
       <xsl:with-param name="docType" select="@docType" />
@@ -190,5 +220,4 @@
 
     <!-- start of iiif_manifest: -->
-    <pre>
     {
         "@context": "http://iiif.io/api/presentation/2/context.json",
@@ -209,5 +238,4 @@
           "@type": "sc:Sequence",
 	  "canvases": [
-    </pre>
 
   </xsl:template>
@@ -215,5 +243,5 @@
   
   <xsl:template name="documentContentSimpleIIIFImage">
-    <xsl:call-template name="iiif-links">
+    <xsl:call-template name="iiif-canvas-image">
       <xsl:with-param name="identifier" select="$docID" />
       <xsl:with-param name="docType" select="@docType" />
@@ -229,185 +257,31 @@
   </xsl:template>
 
+  
+  <xsl:template name="wrapDocumentNodes">
+
+    <xsl:call-template name="sectionContent"/>
+    
+    <xsl:if test="documentNode">
+      <xsl:for-each select="documentNode">
+	<xsl:call-template name="wrapDocumentNodes"/>
+      </xsl:for-each>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template name="wrappedSectionImage">
+    <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
+  </xsl:template>
+
+  
+  
   <xsl:template name="documentPost">
     <!-- end of iiif_manifest: -->
     <!-- close of canvases, then close higher level blocks to complete the JSON file -->
-    <pre>
 	  ]
 	}]	  
     }    	
-    </pre>
-    
-  </xsl:template>
-  
-
-  <xsl:template name="wrappedDocumentTopLevel">
-
-    <!-- <xsl:call-template name="documentPre"/> -->
-    <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
-    <!-- <xsl:call-template name="documentPost"/> -->
-    <!--
-    <xsl:call-template name="documentPostMirador3OLD"/>
-    -->
-
-  </xsl:template>
-
-
-	<xsl:template name="wrapDocumentNodes">
-
-	  <xsl:choose>
-	    <xsl:when test="../../document">
-	      <xsl:call-template name="topLevelSectionContent"/>
-	    </xsl:when>
-	    <xsl:otherwise>
-	      <xsl:call-template name="sectionContent"/>
-	    </xsl:otherwise>
-	  </xsl:choose>
-	  
-	  <xsl:if test="documentNode">
-	    <xsl:for-each select="documentNode">
-	      <xsl:call-template name="wrapDocumentNodes"/>
-	    </xsl:for-each>
-	  </xsl:if>
-	</xsl:template>
-
-
-
-	<xsl:template name="wrappedSectionImage">
-	  <!-- don't need this template to generate anything in the IIIF-Manifest JSON case -->
-	</xsl:template>
-	
-	<!-- The default template for displaying the document node text -->
-	<!-- equivalent to gsf:text -->
-	<xsl:template name="documentNodeText">
-	  <xsl:param name="force">0</xsl:param>
-		<!-- Hides the "This document has no text." message -->
-		<xsl:variable name="noText"><gsf:metadata name="NoText"/></xsl:variable>
-		<xsl:choose>
-		<xsl:when test="$force = '1' or not($noText = '1')">
-
-			<!-- Section text -->
-			<xsl:for-each select="nodeContent">
-			  <xsl:call-template name="displayMarkedUpTextAndAnnotations"/>
-			</xsl:for-each>
-		</xsl:when>
-		<xsl:when test="$noText = '1' and not(metadataList/metadata[@name='ImageType'])">
-			<gsf:link type="source"><gsf:metadata name="Source"/></gsf:link>
-		</xsl:when>
-		</xsl:choose>
-		<xsl:text> </xsl:text>
-	</xsl:template>
-
-
-
-
-
-	<xsl:template match="/page/pageResponse/document">
-		<!-- display the document -->
-		<xsl:choose>
-			<xsl:when test="@docType='simple'">
-				<xsl:call-template name="documentHeading"/><br/>
-				<xsl:call-template name="documentContentTopLevel"/>
-			</xsl:when>	
-			<xsl:otherwise> <!-- display the standard greenstone document -->
-				<xsl:call-template name="wrappedDocumentTopLevel"/>
-			</xsl:otherwise>
-		</xsl:choose>
-	</xsl:template>
-
-
-	<!-- **** SIMPLIFY !!!! -->
-
-	<xsl:template name="wrappedDocument">
-		<xsl:choose>
-			<!-- NOTE: alb = ajax load bypass -->
-			<!-- 
-			     If we have asked for expanded document, then do this.
-			     OR If the docType is hierarchy and we want to bypass the ajax load then do this 
-			     OR If the docType is hierarchy and we have asked for the top level document then do this 
-			-->
-			<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, '.')))))">
-				<div id="gs-document">
-					<xsl:call-template name="documentPre"/>
-					<div id="gs-document-text" class="documenttext" collection="{/page/pageResponse/collection/@name}"><!-- *** -->
-					  <xsl:for-each select="documentNode">
-							<xsl:call-template name="wrapDocumentNodes"/>
-						</xsl:for-each>
-					</div>
-					<xsl:call-template name="documentPost"/>					
-				</div>
-			</xsl:when>
-			<xsl:when test="/page/pageResponse/document/@docType = 'paged' or /page/pageResponse/document/@docType = 'pagedhierarchy'">
-			  <div id="gs-document">
-					<div id="tocLoadingImage" style="text-align:center;">
-						<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>
-					</div>
-				</div>
-				<script type="text/javascript">
-					<xsl:text disable-output-escaping="yes">
-						$(window).on("load", function()
-						{
-							var sectionID = gs.cgiParams.d;
-							var callbackFunction = null;
-							if(sectionID.indexOf(".") != -1)
-							{
-								callbackFunction = function()
-								{
-									focusSection(sectionID);
-								};
-							}
-							else {
-							   callbackFunction = function()
-								{
-								
-								expandAndExecute(sectionID+".1", null, null, null);
-								};
-							}
-							var docID = sectionID.replace(/([^.]*)\..*/, "$1");
-							var url = gs.xsltParams.library_name + "?a=d&amp;c=" + gs.cgiParams.c + "&amp;excerptid=gs-document&amp;dt=hierarchy&amp;d=" + docID;
-							if(gs.cgiParams.p_s) { 
-							url += "&amp;p.s="+gs.cgiParams.p_s;
-							}
-							loadTopLevelPage(callbackFunction, url);
-						});
-					</xsl:text>
-				</script>
-			</xsl:when>
-			<xsl:otherwise>
-				<div id="gs-document">							
-					<div id="tocLoadingImage" style="text-align:center;">
-						<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>
-					</div>
-				</div>
-				<script type="text/javascript">
-					<xsl:text disable-output-escaping="yes">
-						$(window).on("load", function()
-						{
-							loadTopLevelPage(function()
-							{
-								//Don't focus the section until the table of contents is loaded
-								var tocCheck = function()
-								{
-									if(gs.variables.tocLoaded)
-									{
-										focusSection("</xsl:text><xsl:value-of select="/page/pageResponse/document/@selectedNode"/><xsl:text disable-output-escaping="yes">");
-									}
-									else
-									{
-										setTimeout(tocCheck, 500);
-									}
-								}
-								tocCheck();
-							});
-						});
-					</xsl:text>
-				</script>
-			</xsl:otherwise>
-		</xsl:choose>
-		
-		<div class="clear"><xsl:text> </xsl:text></div>
-	</xsl:template>
-
-
-
-	
+    
+  </xsl:template>
+
+
 </xsl:stylesheet>
