Index: /trunk/gsdl3/web/interfaces/default/transform/querytools.xsl
===================================================================
--- /trunk/gsdl3/web/interfaces/default/transform/querytools.xsl	(revision 5193)
+++ /trunk/gsdl3/web/interfaces/default/transform/querytools.xsl	(revision 5194)
@@ -7,33 +7,38 @@
   exclude-result-prefixes="java util">
 
-  <!-- have changed this so it uses service hitsPerPage and startPage if available, otherwise uses interface ones -->
+  <!-- have changed this so it uses service hitsPerPage and startPage if the service description has a param called hitsPerPage,  otherwise uses interface ones -->
   <xsl:template name="resultNavigation">
+    <!-- hits type -->
+    <xsl:variable name='ht'>
+      <xsl:choose>
+	<xsl:when test="/page/pageResponse/service/paramList/param[@name='hitsPerPage']">s</xsl:when>
+	<xsl:otherwise>i</xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    
     <xsl:variable name="param-list" select="/page/pageRequest/paramList"/>
     <!-- hits per page -->
     <xsl:variable name="hpp">
       <xsl:choose>
-	<xsl:when test="$param-list/param[@name='s1.hitsPerPage']"><xsl:value-of select="$param-list/param[@name='s1.hitsPerPage']/@value"/></xsl:when>
+	<xsl:when test="$ht='s'"><xsl:value-of select="$param-list/param[@name='s1.hitsPerPage']/@value"/></xsl:when>
 	<xsl:when test="$param-list/param[@name='hitsPerPage']"><xsl:value-of select="$param-list/param[@name='hitsPerPage']/@value"/></xsl:when>
 	<xsl:otherwise>20</xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
-    <!-- hits type -->
-    <xsl:variable name='ht'>
+    <!-- total docs - this may be in numDocsMatched or numDocsReturned metadata -->
+    <xsl:variable name="td">
       <xsl:choose>
-	<xsl:when test="$param-list/param[@name='s1.hitsPerPage']">s</xsl:when>
-	<xsl:otherwise>i</xsl:otherwise>
+	<xsl:when test="/page/pageResponse/metadataList/metadata[@name='numDocsReturned']">
+	  <xsl:value-of select="/page/pageResponse/metadataList/metadata[@name='numDocsReturned']"/>
+	</xsl:when>
+	<xsl:when test="/page/pageResponse/metadataList/metadata[@name='numDocsMatched']">
+	  <xsl:value-of select="/page/pageResponse/metadataList/metadata[@name='numDocsMatched']"/>
+	</xsl:when>
+	<xsl:otherwise> <!-- this is just a fall back - shoudl always have the metadata -->
+	  <xsl:value-of select="count(/page/pageResponse/documentNodeList/documentNode)"/>
+	</xsl:otherwise>	
       </xsl:choose>
     </xsl:variable>
-    <!-- total docs -->
-    <xsl:variable name="td">
-      <xsl:choose>
-	<xsl:when test="$ht='s'">
-	  <xsl:value-of select="/page/pageResponse/metadataList/metadata[@name='numDocsMatched']/@value"/>
-	</xsl:when>
-	<xsl:otherwise>
-	  <xsl:value-of select="count(/page/pageResponse/documentNodeList/documentNode)"/>
-	</xsl:otherwise>
-      </xsl:choose>
-    </xsl:variable>
+
     <!-- only continue if hpp != -1 and td > hpp -->
     <xsl:if test="not($hpp=-1) and $td &gt; $hpp">
@@ -41,5 +46,5 @@
       <xsl:variable name="here">
 	<xsl:choose>
-	  <xsl:when test="$param-list/param[@name='s1.startPage']"><xsl:value-of select="$param-list/param[@name='s1.startPage']/@value"/></xsl:when>
+	  <xsl:when test="$ht='s'"><xsl:value-of select="$param-list/param[@name='s1.startPage']/@value"/></xsl:when>
 	  <xsl:when test="$param-list/param[@name='startPage']"><xsl:value-of select="$param-list/param[@name='startPage']/@value"/></xsl:when>
 	  <xsl:otherwise>1</xsl:otherwise>
@@ -67,5 +72,40 @@
     </xsl:if>
   </xsl:template>
-  
+    
+  <xsl:template name="matchDocs">
+    <!-- If the number of matching documents is known, display it -->
+    <xsl:variable name="numDocsMatched" select="metadataList/metadata[@name='numDocsMatched']"/>
+    <xsl:variable name="numDocsReturned" select="metadataList/metadata[@name='numDocsReturned']"/>
+    <xsl:choose>
+      <xsl:when test="$numDocsMatched='0' or $numDocsReturned='0'">
+	<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.nodocsmatch')"/>
+      </xsl:when>
+      <xsl:when test="$numDocsMatched='1' or $numDocsReturned='0'">
+	<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.onedocsmatch')"/>
+      </xsl:when>
+      <xsl:when test="$numDocsMatched">
+	<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.manydocsmatch', $numDocsMatched)"/>
+	<xsl:if test="$numDocsReturned"> (<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.docsreturned', $numDocsReturned)"/>)</xsl:if>
+      </xsl:when>
+      <xsl:when test="$numDocsReturned">
+	<xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.atleastdocsmatch', $numDocsReturned)"/>
+      </xsl:when>
+    </xsl:choose>
+  </xsl:template>
+
+  <!-- paging is now done by the query action, so here we just print out all the docs that we have -->
+  <xsl:template name="resultList">
+    <xsl:param name="collName"/>
+    <table>
+      <xsl:for-each select="documentNodeList/documentNode">
+	<tr>
+	  <xsl:apply-templates select=".">
+	    <xsl:with-param name="collName" select="$collName"/>
+	  </xsl:apply-templates>
+	</tr>	    
+      </xsl:for-each>
+    </table>    
+  </xsl:template>
+
 
   <!-- the default doc node template for the query results -->
@@ -93,72 +133,4 @@
     </xsl:if>
   </xsl:template>
-  
-  <xsl:template name="matchDocs">
-    <!-- If the number of matching documents is known, display it -->
-    <xsl:variable name="numDocsMatched" select="metadataList/metadata[@name='numDocsMatched']/@value"/>
-    <xsl:if test="$numDocsMatched">
-      <xsl:choose>
-	<xsl:when test="$numDocsMatched='0'">
-	  <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.nodocsmatch')"/>
-	</xsl:when>
-	<xsl:when test="$numDocsMatched='1'">
-	  <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.onedocsmatch')"/>
-	</xsl:when>
-	<xsl:otherwise>
-	  <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'query.manydocsmatch', $numDocsMatched)"/>
-	</xsl:otherwise>
-      </xsl:choose>
-    </xsl:if>
-  </xsl:template>
-
-
-  <xsl:template name="resultList">
-    <xsl:param name="collName"/>
-    <xsl:variable name="param-list" select="/page/pageRequest/paramList"/>
-    <!-- hits per page -->
-    <xsl:variable name="hpp">
-      <xsl:choose>
-	<xsl:when test="$param-list/param[@name='s1.hitsPerPage']"><xsl:value-of select="$param-list/param[@name='s1.hitsPerPage']/@value"/></xsl:when>
-	<xsl:when test="$param-list/param[@name='hitsPerPage']"><xsl:value-of select="$param-list/param[@name='hitsPerPage']/@value"/></xsl:when>
-	<xsl:otherwise>20</xsl:otherwise>
-      </xsl:choose>
-    </xsl:variable>
-    <xsl:choose>
-      <xsl:when test="$param-list/param[@name='s1.hitsPerPage'] or $hpp=-1">
-	<!-- the service has handled the paging, just output all the docs -->
-	<table>
-	  <xsl:for-each select="documentNodeList/documentNode">
-	    <tr>
-	      <xsl:apply-templates select=".">
-		<xsl:with-param name="collName" select="$collName"/>
-	      </xsl:apply-templates>
-	    </tr>	    
-	  </xsl:for-each>
-	</table>
-      </xsl:when>
-      <xsl:otherwise>
-	<!-- we have done the paging, only show a selection of the docs -->
-	<!-- start page -->
-	<xsl:variable name="sp">
-	  <xsl:choose>
-	    <xsl:when test="$param-list/param[@name='s1.startPage']"><xsl:value-of select="$param-list/param[@name='s1.startPage']/@value"/></xsl:when>
-	    <xsl:when test="$param-list/param[@name='startPage']"><xsl:value-of select="$param-list/param[@name='startPage']/@value"/></xsl:when>
-	    <xsl:otherwise>1</xsl:otherwise>
-	  </xsl:choose>
-	</xsl:variable>
-	<table>
-	  <xsl:for-each select="documentNodeList/documentNode">
-	    <xsl:if test=" (position()&gt; (($sp - 1)*$hpp) and position() &lt;= ($sp * $hpp))">
-	      <tr>
-		<xsl:apply-templates select=".">
-		  <xsl:with-param name="collName" select="$collName"/>
-		</xsl:apply-templates>
-	      </tr>
-	    </xsl:if>
-	  </xsl:for-each>
-	</table>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
 
 </xsl:stylesheet>
