From 7a34c266d31e6396166941867e25f1386b2eca2e Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Fri, 21 Dec 2012 15:37:43 +0100
Subject: [PATCH] Bug 7441: Followup search results showing wrong branch [UNIMARC]

Unimarc modifications

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
---
 .../prog/en/xslt/UNIMARCslim2OPACResults.xsl       |   98 +++++++++++--------
 1 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl
index a086d31..77315e1 100644
--- a/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl
+++ b/koha-tmpl/opac-tmpl/prog/en/xslt/UNIMARCslim2OPACResults.xsl
@@ -11,7 +11,9 @@
 <xsl:import href="UNIMARCslimUtils.xsl"/>
 <xsl:output method = "html" indent="yes" omit-xml-declaration = "yes" encoding="UTF-8"/>
 <xsl:key name="item-by-status" match="items:item" use="items:status"/>
-<xsl:key name="item-by-status-and-branch" match="items:item" use="concat(items:status, ' ', items:homebranch)"/>
+<xsl:key name="item-by-status-and-branch-holding" match="items:item" use="concat(items:status, ' ', items:holdingbranch)"/>
+<xsl:key name="item-by-status-and-branch-home"    match="items:item" use="concat(items:status, ' ', items:homebranch)"/>
+
 
 <xsl:template match="/">
   <xsl:apply-templates/>
@@ -26,6 +28,7 @@
   <xsl:variable name="isbn"
    select="marc:datafield[@tag=010]/marc:subfield[@code='a']"/>
 
+  <xsl:variable name="OPACResultsBranchXSLT" select="marc:sysprefs/marc:syspref[@name='OPACResultsBranchXSLT']"/>
   <xsl:variable name="hidelostitems" select="marc:sysprefs/marc:syspref[@name='hidelostitems']"/>
   <xsl:variable name="singleBranchMode" select="marc:sysprefs/marc:syspref[@name='singleBranchMode']"/>
 
@@ -133,33 +136,39 @@
           <b><xsl:text>Copies available for loan: </xsl:text></b>
           <xsl:variable name="available_items" select="key('item-by-status', 'available')"/>
       <xsl:choose>
-      <xsl:when test="$singleBranchMode=1">
-      <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
-        <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
-          <xsl:text> (</xsl:text>
-          <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
-          <xsl:text>)</xsl:text>
-          <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
-      </xsl:for-each>
-      </xsl:when>
-      <xsl:otherwise>
-          <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
-            <xsl:value-of select="items:homebranch"/>
-  			    <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]
-  			    </xsl:if>
+        <xsl:when test="$singleBranchMode=1">
+          <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch))[1])]">
+            <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
             <xsl:text> (</xsl:text>
-            <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
+            <xsl:value-of select="count(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch)))"/>
             <xsl:text>)</xsl:text>
-            <xsl:choose>
-              <xsl:when test="position()=last()">
-                <xsl:text>. </xsl:text>
-              </xsl:when>
-              <xsl:otherwise>
-                <xsl:text>, </xsl:text>
-              </xsl:otherwise>
-            </xsl:choose>
+            <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
           </xsl:for-each>
-      </xsl:otherwise>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:choose>
+            <xsl:when test="$OPACResultsBranchXSLT='homebranch'">
+              <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch))[1])]">
+                <xsl:value-of select="items:homebranch"/>
+                <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
+                <xsl:text> (</xsl:text>
+                <xsl:value-of select="count(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch)))"/>
+                <xsl:text>)</xsl:text>
+                <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
+              </xsl:for-each>
+            </xsl:when>
+            <xsl:when test="$OPACResultsBranchXSLT='holdingbranch'">
+              <xsl:for-each select="$available_items[generate-id() = generate-id(key('item-by-status-and-branch-holding', concat(items:status, ' ', items:holdingbranch))[1])]">
+                <xsl:value-of select="items:holdingbranch"/>
+                <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
+                <xsl:text> (</xsl:text>
+                <xsl:value-of select="count(key('item-by-status-and-branch-holding', concat(items:status, ' ', items:holdingbranch)))"/>
+                <xsl:text>)</xsl:text>
+                <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
+              </xsl:for-each>
+            </xsl:when>
+          </xsl:choose>
+        </xsl:otherwise>
       </xsl:choose>
         </span>
       </xsl:when>
@@ -168,23 +177,30 @@
       <xsl:when test="count(key('item-by-status', 'reference'))>0">
         <span class="available">
           <b><xsl:text>Copies available for reference: </xsl:text></b>
-          <xsl:variable name="reference_items"
-                        select="key('item-by-status', 'reference')"/>
-          <xsl:for-each select="$reference_items[generate-id() = generate-id(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch))[1])]">
-            <xsl:value-of select="items:homebranch"/>
-            <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber">[<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
-            <xsl:text> (</xsl:text>
-            <xsl:value-of select="count(key('item-by-status-and-branch', concat(items:status, ' ', items:homebranch)))"/>
-            <xsl:text>)</xsl:text>
-            <xsl:choose>
-              <xsl:when test="position()=last()">
-                <xsl:text>. </xsl:text>
+          <xsl:variable name="reference_items" select="key('item-by-status', 'reference')"/>
+
+          <xsl:choose>
+              <xsl:when test="$OPACResultsBranchXSLT='homebranch'">
+                  <xsl:for-each select="$reference_items[generate-id() = generate-id(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch))[1])]">
+                      <xsl:value-of select="items:homebranch"/>
+                      <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
+                      <xsl:text> (</xsl:text>
+                      <xsl:value-of select="count(key('item-by-status-and-branch-home', concat(items:status, ' ', items:homebranch)))"/>
+                      <xsl:text>)</xsl:text>
+                      <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
+                  </xsl:for-each>
               </xsl:when>
-              <xsl:otherwise>
-                <xsl:text>, </xsl:text>
-              </xsl:otherwise>
-            </xsl:choose>
-          </xsl:for-each>
+              <xsl:when test="$OPACResultsBranchXSLT='holdingbranch'">
+                  <xsl:for-each select="$reference_items[generate-id() = generate-id(key('item-by-status-and-branch-holding', concat(items:status, ' ', items:holdingbranch))[1])]">
+                      <xsl:value-of select="items:holdingbranch"/>
+                      <xsl:if test="items:itemcallnumber != '' and items:itemcallnumber"> [<xsl:value-of select="items:itemcallnumber"/>]</xsl:if>
+                      <xsl:text> (</xsl:text>
+                      <xsl:value-of select="count(key('item-by-status-and-branch-holding', concat(items:status, ' ', items:holdingbranch)))"/>
+                      <xsl:text>)</xsl:text>
+                      <xsl:choose><xsl:when test="position()=last()"><xsl:text>. </xsl:text></xsl:when><xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise></xsl:choose>
+                  </xsl:for-each>
+              </xsl:when>
+          </xsl:choose>
         </span>
       </xsl:when>
     </xsl:choose>
-- 
1.7.2.5