Index: main/trunk/greenstone3/web/interfaces/default/transform/config_format.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/transform/config_format.xsl	(revision 26459)
+++ main/trunk/greenstone3/web/interfaces/default/transform/config_format.xsl	(revision 26460)
@@ -11,5 +11,5 @@
 	<xsl:param name="site_name"/>
 	<xsl:param name="collName"/>
-  
+
 	<xsl:output method="xml"/>
 	<xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/>
@@ -20,5 +20,5 @@
 		</format>
 	</xsl:template>
-  
+
 	<xsl:template match="gsf:template">
 		<xslt:template>
@@ -32,5 +32,5 @@
 		</xslt:template>
 	</xsl:template>
-	
+
 	<xsl:template match="gsf:variable">
 		<xslt:variable>
@@ -39,8 +39,11 @@
 		</xslt:variable>
 		<script type="text/javascript">
-			gs.variables.<xsl:value-of select="@name"/><xslt:text disable-output-escaping="yes"> = "</xslt:text><xsl:apply-templates/><xslt:text disable-output-escaping="yes">";</xslt:text>
+			gs.variables.<xsl:value-of select="@name"/>
+			<xslt:text disable-output-escaping="yes"> = "</xslt:text>
+			<xsl:apply-templates/>
+			<xslt:text disable-output-escaping="yes">";</xslt:text>
 		</script>
 	</xsl:template>
-	
+
 	<xsl:template match="gsf:defaultClassifierNode">
 		<xslt:call-template name="defaultClassifierNode"/>
@@ -49,35 +52,36 @@
 
 	<xsl:template match="gsf:script[@src]">
-	  <script>
-	    <xsl:attribute name='src'>
-	      <xsl:value-of select="@src"/>		
-	    </xsl:attribute>
-	    <xslt:attribute name='type'>text/javascript</xslt:attribute>
-	    <xslt:comment></xslt:comment><!-- comment used to ensure script tag is not collapsed -->
-	  </script>
+		<script>
+			<xsl:attribute name='src'>
+				<xsl:value-of select="@src"/>		
+			</xsl:attribute>
+			<xslt:attribute name='type'>text/javascript</xslt:attribute>
+			<xslt:comment/>
+			<!-- comment used to ensure script tag is not collapsed -->
+		</script>
 	</xsl:template>
 
 
 	<xsl:template match="gsf:script">
-	  <script type="text/javascript">
-	    <xslt:text disable-output-escaping="yes">
-	      <xsl:apply-templates/>
-	    </xslt:text>
-	  </script>
+		<script type="text/javascript">
+			<xslt:text disable-output-escaping="yes">
+				<xsl:apply-templates/>
+			</xslt:text>
+		</script>
 	</xsl:template>
 
 
 	<xsl:template match="gsf:style[@src]">
-	  <link rel="stylesheet" type="text/css">
-	    <xsl:attribute name='href'>
-	      <xsl:value-of select="@src"/>		
-	    </xsl:attribute>
-	  </link>
+		<link rel="stylesheet" type="text/css">
+			<xsl:attribute name='href'>
+				<xsl:value-of select="@src"/>		
+			</xsl:attribute>
+		</link>
 	</xsl:template>
 
 	<xsl:template match="gsf:style">
-	  <style type="text/css">
-	      <xsl:apply-templates/>
-	  </style>
+		<style type="text/css">
+			<xsl:apply-templates/>
+		</style>
 	</xsl:template>
 
@@ -105,11 +109,19 @@
 
 	<xsl:template match="gsf:link">
-    <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
-    <xsl:variable name="opt-title">					
-      <xsl:choose>
-	<xsl:when test="@title"><xslt:attribute name="title"><xsl:value-of select="@title"/></xslt:attribute></xsl:when>
-	<xsl:when test="@titlekey"><xslt:attribute name="title"><xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collName, $site_name, /page/@lang, '{@titlekey}')"/></xslt:attribute></xsl:when>
-      </xsl:choose>
-    </xsl:variable>
+		<xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
+		<xsl:variable name="opt-title">					
+			<xsl:choose>
+				<xsl:when test="@title">
+					<xslt:attribute name="title">
+						<xsl:value-of select="@title"/>
+					</xslt:attribute>
+				</xsl:when>
+				<xsl:when test="@titlekey">
+					<xslt:attribute name="title">
+						<xslt:value-of disable-output-escaping="yes" select="util:getCollectionText($collName, $site_name, /page/@lang, '{@titlekey}')"/>
+					</xslt:attribute>
+				</xsl:when>
+			</xsl:choose>
+		</xsl:variable>
 		<xsl:choose>
 			<xsl:when test="@type='query'">
@@ -129,5 +141,5 @@
 						</xsl:choose>
 					</xslt:attribute>
-                                        <xsl:copy-of select="$opt-title"/>
+					<xsl:copy-of select="$opt-title"/>
 					<xsl:apply-templates/>
 				</a>
@@ -149,21 +161,24 @@
 						</xsl:choose>
 					</xslt:attribute>
-                                        <xsl:copy-of select="$opt-title"/>
+					<xsl:copy-of select="$opt-title"/>
 					<xsl:apply-templates/>
 				</a>
 			</xsl:when>
 			<xsl:when test="@type='source'">
-				<a><xslt:attribute name='href'><xslt:value-of 
+				<a>
+					<xslt:attribute name='href'>
+						<xslt:value-of 
 				   disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']" />/index/assoc/<xslt:value-of 
 				   disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='assocfilepath']" />/<xslt:value-of 
-				   disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='srclinkFile']" /></xslt:attribute>
-                                  <xsl:copy-of select="$opt-title"/>
-				  <xsl:apply-templates/>
+				   disable-output-escaping="yes" select="(.//metadataList)[last()]/metadata[@name='srclinkFile']" />
+					</xslt:attribute>
+					<xsl:copy-of select="$opt-title"/>
+					<xsl:apply-templates/>
 				</a>
 			</xsl:when>
 			<xsl:when test="@type='web'">
-	<xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'weblink')]"/>
-			  <xsl:apply-templates/>
-			  <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, '/weblink')]"/>
+				<xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'weblink')]"/>
+				<xsl:apply-templates/>
+				<xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, '/weblink')]"/>
 			</xsl:when>
 			<xsl:when test="@type='page'">
@@ -176,17 +191,18 @@
 						<xsl:value-of select="@page"/>
 					</xslt:attribute>
-	                                <xsl:copy-of select="$opt-title"/>
-				<xsl:apply-templates/>
+					<xsl:copy-of select="$opt-title"/>
+					<xsl:apply-templates/>
 				</a>	
 			</xsl:when>
 			<xsl:when test="@type='equivdoc'">
-			  <xsl:call-template name="gsf:equivlinkgs3"/>
-			</xsl:when>
-			<xsl:otherwise> <!-- a document link -->
+				<xsl:call-template name="gsf:equivlinkgs3"/>
+			</xsl:when>
+			<xsl:otherwise>
+				<!-- a document link -->
 				<xslt:variable name="bookswitch">
 					<xslt:value-of select="/page/pageRequest/paramList/param[@name='book']/@value"/>
 				</xslt:variable>
 				<a>
-	                          <xsl:copy-of select="$opt-title"/>
+					<xsl:copy-of select="$opt-title"/>
 					<xslt:attribute name="href">
 						<xslt:value-of select='$library_name'/>
@@ -194,6 +210,16 @@
 						<xslt:value-of select='/page/pageResponse/collection/@name'/>
 						<xsl:text>/document/</xsl:text>
-	    <xsl:choose><xsl:when test="@OID"><xsl:value-of select="@OID"/></xsl:when><xsl:when test="@OIDmetadata"><xsl:variable name="OIDmeta" select="@OIDmetadata"/><xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$OIDmeta}']"/></xsl:when><xsl:otherwise>
-						<xslt:value-of select='@nodeID'/></xsl:otherwise></xsl:choose>
+						<xsl:choose>
+							<xsl:when test="@OID">
+								<xsl:value-of select="@OID"/>
+							</xsl:when>
+							<xsl:when test="@OIDmetadata">
+								<xsl:variable name="OIDmeta" select="@OIDmetadata"/>
+								<xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$OIDmeta}']"/>
+							</xsl:when>
+							<xsl:otherwise>
+								<xslt:value-of select='@nodeID'/>
+							</xsl:otherwise>
+						</xsl:choose>
 						<xslt:choose>
 							<xslt:when test="$bookswitch = 'on' or $bookswitch = 'flashxml'">
@@ -201,5 +227,6 @@
 							</xslt:when>
 							<xslt:otherwise>
-								<xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/></xslt:if>
+								<xslt:if test="$opt-doc-link-args">?<xslt:value-of select="$opt-doc-link-args"/>
+								</xslt:if>
 							</xslt:otherwise>
 						</xslt:choose>
@@ -214,41 +241,49 @@
 		<xsl:choose>
 			<xsl:when test="@type='classifier'">
-				<img style="border:0px"><xsl:attribute name="src"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/></xsl:attribute></img>
+				<img style="border:0px">
+					<xsl:attribute name="src">
+						<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/>
+					</xsl:attribute>
+				</img>
 			</xsl:when>
 			<xsl:when test="@type='web'">
-			  <xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>				
+				<xslt:value-of disable-output-escaping="yes" select="metadataList/metadata[contains(@name, 'webicon')]"/>				
 			</xsl:when>
 			<xsl:when test="@file">
-			  <img>
-			    <xslt:attribute name='src'>
-			      <xsl:choose>
-				<xsl:when test="not(@select) or @select='site'">
-				  <xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
-				</xsl:when>
-				<xsl:when test="@select='collection'">
-				  <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
-				  <xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
-				</xsl:when>
-			      </xsl:choose>				
-			    </xslt:attribute>
-			  </img>
+				<img>
+					<xslt:attribute name='src'>
+						<xsl:choose>
+							<xsl:when test="not(@select) or @select='site'">
+								<xsl:value-of disable-output-escaping="yes" select="concat('interfaces/',$interface_name,'/images/',@file)"/>
+							</xsl:when>
+							<xsl:when test="@select='collection'">
+								<xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>
+								<xsl:value-of disable-output-escaping="yes" select="concat('/images/',@file)"/>
+							</xsl:when>
+						</xsl:choose>				
+					</xslt:attribute>
+				</img>
 			</xsl:when>
 			<xsl:when test="not(@type) or @type='document'">
-				<img style="border:0px"><xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/></xslt:attribute><xslt:attribute name="src">
-					<xslt:choose>
-						<xslt:when test="@docType='hierarchy' and @nodeType='root'">
-							<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
-						</xslt:when>
-						<xslt:otherwise>
-							<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
-						</xslt:otherwise>
-					</xslt:choose>
-				</xslt:attribute></img> 
+				<img style="border:0px">
+					<xslt:attribute name="id">documentBasketBook<xslt:value-of select="/page/pageResponse/collection/@name"/>:<xslt:value-of select="@nodeID"/>
+					</xslt:attribute>
+					<xslt:attribute name="src">
+						<xslt:choose>
+							<xslt:when test="@docType='hierarchy' and @nodeType='root'">
+								<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/>
+							</xslt:when>
+							<xslt:otherwise>
+								<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/>
+							</xslt:otherwise>
+						</xslt:choose>
+					</xslt:attribute>
+				</img> 
 			</xsl:when>
 		</xsl:choose>
 	</xsl:template>
-	
-  <!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
-  <!--<xsl:template match="gsf:equivlinkgs3">
+
+	<!-- calls a template in gslib.xsl in order to avoid xsl vs xslt issue -->
+	<!--<xsl:template match="gsf:equivlinkgs3">
     <xslt:call-template name="equivDocLinks">
       <xslt:with-param name="count" select="0"/>
@@ -256,15 +291,15 @@
   </xsl:template>-->
 
-  <!-- Another way (also works with DSpace tutorial): build all the equivalent document links for the current document in one go. No looping necessary: handled in function call. -->
-  <xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
-	<xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>	
-	<xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>	
-	<xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
-
-	<xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
-	<xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
-  </xsl:template>
-
-<!--
+	<!-- Another way (also works with DSpace tutorial): build all the equivalent document links for the current document in one go. No looping necessary: handled in function call. -->
+	<xsl:template match="gsf:equivlinkgs3" name="gsf:equivlinkgs3">
+		<xslt:variable name="docicon" select="metadataList/metadata[contains(@name, 'equivDocIcon')]"/>	
+		<xslt:variable name="docStartlink" select="metadataList/metadata[contains(@name, 'all_*,*_equivDocLink')]"/>	
+		<xslt:variable name="docEndlink" select="metadataList/metadata[contains(@name, '/equivDocLink')]"/>
+
+		<xslt:variable name="equivDocLinks" select="java:org.greenstone.gsdl3.util.XSLTUtil.getEquivDocLinks(',',$docicon, $docStartlink, $docEndlink, ' ')" />
+		<xslt:value-of disable-output-escaping="yes" select="$equivDocLinks"/>
+	</xsl:template>
+
+	<!--
 In the collection's format statement, could have the following javascript+XSLT in place of
 the gsf:equivlinkgs3 element (which resolves to the XSLT in config_format.xsl and gslib.xsl).
@@ -292,41 +327,41 @@
 	  If the requested string occurs in neither, the request string itself will be output. -->
 	<xsl:template match="gsf:displayText">
-	  <xslt:variable name="displaytext">
-	    <xsl:call-template name="gsf:displayItem"/>
-	  </xslt:variable>
-
-	  <xslt:choose>
-	    <xslt:when test="$displaytext != ''">
-	      <xslt:value-of disable-output-escaping="yes" select="$displaytext"/>	      
-	    </xslt:when>
-	    <xslt:otherwise>
-	      <xslt:variable name="interfacetxt">
-		<xsl:call-template name="gsf:interfaceText"/>
-	      </xslt:variable>
-
-	      <xslt:choose>
-		<xslt:when test="$interfacetxt != ''">
-		  <xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
-		</xslt:when>
-		<xslt:otherwise>
-		  <xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
-		</xslt:otherwise>
-	      </xslt:choose>
-	    </xslt:otherwise>
-	  </xslt:choose>
+		<xslt:variable name="displaytext">
+			<xsl:call-template name="gsf:displayItem"/>
+		</xslt:variable>
+
+		<xslt:choose>
+			<xslt:when test="$displaytext != ''">
+				<xslt:value-of disable-output-escaping="yes" select="$displaytext"/>	      
+			</xslt:when>
+			<xslt:otherwise>
+				<xslt:variable name="interfacetxt">
+					<xsl:call-template name="gsf:interfaceText"/>
+				</xslt:variable>
+
+				<xslt:choose>
+					<xslt:when test="$interfacetxt != ''">
+						<xslt:value-of disable-output-escaping="yes" select="$interfacetxt"/>
+					</xslt:when>
+					<xslt:otherwise>
+						<xslt:value-of disable-output-escaping="yes" select="'{@name}'"/>
+					</xslt:otherwise>
+				</xslt:choose>
+			</xslt:otherwise>
+		</xslt:choose>
 	</xsl:template>
 
 	<!-- With gsf:displayItem, a user can request a displayItem from collectionConfig.xml -->
 	<xsl:template match="gsf:displayItem" name="gsf:displayItem">
-	  <xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItem[@name='{@name}']"/>
+		<xslt:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/displayItem[@name='{@name}']"/>
 	</xsl:template>
 
 	<!-- With gsf:interfaceText, a user can request a string from the interface dictionaries in the current lang -->
 	<xsl:template match="gsf:interfaceText" name="gsf:interfaceText">
-	  <xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
+		<xslt:value-of disable-output-escaping="yes" select="util:getInterfaceText($interface_name, /page/@lang, '{@name}')"/>
 	</xsl:template>
 	<!-- With gsf:collectionText, a user can request a string from the collection's dictionary in the current lang -->
 	<xsl:template match="gsf:collectionText" name="gsf:collectionText">
-    <xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
+		<xslt:variable name="collName" select="/page/pageResponse/collection/@name"/>
 		<xslt:copy-of select="util:getCollectionText($collName, $site_name, /page/@lang, '{@name}', '{@args}')/node()"/>
 	</xsl:template>
@@ -336,22 +371,38 @@
 		<xsl:if test="not(@hidden = 'true')">
 			<!-- set hidden=true on a gsf:metadata so that it gets retrieved from the server but not displayed -->
-			<xsl:variable name="meta_name"><xsl:call-template name="getMetadataName"/></xsl:variable>
+			<xsl:variable name="meta_name">
+				<xsl:call-template name="getMetadataName"/>
+			</xsl:variable>
 			<xsl:variable name="separator">
 				<xsl:choose>
-					<xsl:when test="@separator"><xsl:value-of disable-output-escaping='yes' select="@separator"/></xsl:when>
-					<xsl:when test="separator"><xsl:copy-of select="separator/node()"/></xsl:when>
-					<xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise>
+					<xsl:when test="@separator">
+						<xsl:value-of disable-output-escaping='yes' select="@separator"/>
+					</xsl:when>
+					<xsl:when test="separator">
+						<xsl:copy-of select="separator/node()"/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:text>, </xsl:text>
+					</xsl:otherwise>
 				</xsl:choose>
 			</xsl:variable>
 			<xsl:variable name="prefix">
 				<xsl:choose>
-					<xsl:when test="@prefix"><xsl:value-of disable-output-escaping='yes' select="@prefix"/></xsl:when>
-					<xsl:when test="prefix"><xsl:copy-of select="prefix/node()"/></xsl:when>
+					<xsl:when test="@prefix">
+						<xsl:value-of disable-output-escaping='yes' select="@prefix"/>
+					</xsl:when>
+					<xsl:when test="prefix">
+						<xsl:copy-of select="prefix/node()"/>
+					</xsl:when>
 				</xsl:choose>
 			</xsl:variable>
 			<xsl:variable name="suffix">
 				<xsl:choose>
-					<xsl:when test="@suffix"><xsl:value-of disable-output-escaping='yes' select="@suffix"/></xsl:when>
-					<xsl:when test="suffix"><xsl:copy-of select="suffix/node()"/></xsl:when>
+					<xsl:when test="@suffix">
+						<xsl:value-of disable-output-escaping='yes' select="@suffix"/>
+					</xsl:when>
+					<xsl:when test="suffix">
+						<xsl:copy-of select="suffix/node()"/>
+					</xsl:when>
 				</xsl:choose>
 			</xsl:variable>
@@ -360,5 +411,6 @@
 					<xsl:when test="@pos = 'first'">position()=1</xsl:when>
 					<xsl:when test="@pos = 'last'">position() = last()</xsl:when>
-					<xsl:when test="@pos">position() = <xsl:value-of select="@pos"/></xsl:when>
+					<xsl:when test="@pos">position() = <xsl:value-of select="@pos"/>
+					</xsl:when>
 					<xsl:otherwise>true()</xsl:otherwise>
 				</xsl:choose>
@@ -372,8 +424,13 @@
 			<xslt:for-each>
 				<xsl:attribute name="select">
-					<xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>(.//metadataList)[last()]/metadata[@name='<xsl:value-of select="$meta_name"/>'<xsl:if test="@lang"><xsl:text> and @lang=</xsl:text><xsl:value-of select="@lang"/></xsl:if><xsl:text>]</xsl:text>
+					<xsl:if test="@type='collection'">/page/pageResponse/collection/</xsl:if>(.//metadataList)[last()]/metadata[@name='<xsl:value-of select="$meta_name"/>'<xsl:if test="@lang">
+						<xsl:text> and @lang=</xsl:text>
+						<xsl:value-of select="@lang"/>
+					</xsl:if>
+					<xsl:text>]</xsl:text>
 				</xsl:attribute>
 				<xslt:if test="{$postest}">
-					<xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/></xslt:if>
+					<xslt:if test="{$multiple} and position()>1"><xsl:copy-of select="$separator"/>
+					</xslt:if>
 					<xsl:copy-of select="$prefix"/>
 					<xsl:choose>
@@ -391,28 +448,31 @@
 	</xsl:template>
 
-  <xsl:template name="getMetadataName">
-    <xsl:if test='@select'>
-      <xsl:value-of select='@select'/>
-      <xsl:text>_</xsl:text>
-    </xsl:if>
-    <xsl:value-of select="@name"/>
-  </xsl:template>
+	<xsl:template name="getMetadataName">
+		<xsl:if test='@select'>
+			<xsl:value-of select='@select'/>
+			<xsl:text>_</xsl:text>
+		</xsl:if>
+		<xsl:value-of select="@name"/>
+	</xsl:template>
 
 	<xsl:template match="gsf:text">
 		<xslt:call-template name="documentNodeText"/>
 	</xsl:template>
-  
-  <xsl:template match="gsf:if-metadata-exists">
-    <xsl:variable name="meta-path"><xsl:for-each select="gsf:metadata">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:for-each></xsl:variable>
-    <xslt:choose>
-	<xslt:when test="{$meta-path}">
-	  <xsl:apply-templates select="gsf:if/node()"/>
-	</xslt:when>
-      <xsl:if test="gsf:else">
-	<xslt:otherwise><xsl:apply-templates select="gsf:else/node()"/>
-	</xslt:otherwise>
-      </xsl:if>
-    </xslt:choose>
-  </xsl:template>
+
+	<xsl:template match="gsf:if-metadata-exists">
+		<xsl:variable name="meta-path">
+			<xsl:for-each select="gsf:metadata">(.//metadataList)[last()]/metadata[@name='<xsl:call-template name="getMetadataName"/>']</xsl:for-each>
+		</xsl:variable>
+		<xslt:choose>
+			<xslt:when test="{$meta-path}">
+				<xsl:apply-templates select="gsf:if/node()"/>
+			</xslt:when>
+			<xsl:if test="gsf:else">
+				<xslt:otherwise>
+					<xsl:apply-templates select="gsf:else/node()"/>
+				</xslt:otherwise>
+			</xsl:if>
+		</xslt:choose>
+	</xsl:template>
 
 	<xsl:template match="gsf:choose-metadata">
@@ -425,12 +485,27 @@
 			</xsl:for-each>
 			<xsl:if test="gsf:default">
-				<xslt:otherwise><xsl:apply-templates select="gsf:default"/></xslt:otherwise>
+				<xslt:otherwise>
+					<xsl:apply-templates select="gsf:default"/>
+				</xslt:otherwise>
 			</xsl:if>
 		</xslt:choose>
 	</xsl:template>
-  
+
 	<xsl:template match="gsf:switch">
-		<xsl:variable name="meta-name"><xsl:for-each select="gsf:metadata"><xsl:call-template name="getMetadataName"/></xsl:for-each></xsl:variable>
-		<xslt:variable name="meta"><xsl:choose><xsl:when test="@preprocess"><xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'], /page/@lang )"/></xsl:when><xsl:otherwise><xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/></xsl:otherwise></xsl:choose></xslt:variable>
+		<xsl:variable name="meta-name">
+			<xsl:for-each select="gsf:metadata">
+				<xsl:call-template name="getMetadataName"/>
+			</xsl:for-each>
+		</xsl:variable>
+		<xslt:variable name="meta">
+			<xsl:choose>
+				<xsl:when test="@preprocess">
+					<xslt:value-of select="util:{@preprocess}((.//metadataList)[last()]/metadata[@name='{$meta-name}'], /page/@lang )"/>
+				</xsl:when>
+				<xsl:otherwise>
+					<xslt:value-of select="(.//metadataList)[last()]/metadata[@name='{$meta-name}']"/>
+				</xsl:otherwise>
+			</xsl:choose>
+		</xslt:variable>
 		<xslt:choose>
 			<xsl:for-each select="gsf:when">
@@ -446,8 +521,8 @@
 		</xslt:choose>
 	</xsl:template>
-  
+
 	<xsl:template match="*">
 		<xsl:copy>
-		<xsl:copy-of select="@*"/>
+			<xsl:copy-of select="@*"/>
 			<xsl:apply-templates/>
 		</xsl:copy>
