From 2771b60f90b5292ecc9814e3aeab1e1f4a0907eb Mon Sep 17 00:00:00 2001
From: George Veranis <gveranis@dataly.gr>
Date: Thu, 14 Sep 2023 08:24:07 +0200
Subject: [PATCH] Bug 29539: UNIMARC: authority number in $9 displays for
 thesaurus controlled fields instead of content of $a

When you try to dislpay a bibliographic record on unimarc that has subjects
linked with authorities then only the $9 is displayed as link instead of the
content of $a and it's subdivisions, if any.

To test:
1) You will need to have a bibliographic record with at least one subject
autority connected in unimarc framework.
2) View that record on OPAC on detail display. The subject will display as
a number ( $9 )  and you cannot see the text/term of the subject ( $a )
3) Apply patch
4) Repeat step 2
5) The subject display in a normal way based on content $a - or more subfields

Sponsored-by: National Library of Greece
---
 .../bootstrap/en/xslt/UNIMARCslimUtils.xsl    | 30 +++++++++++++++----
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/UNIMARCslimUtils.xsl b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/UNIMARCslimUtils.xsl
index dc02e6fc8e..1d567eab32 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/UNIMARCslimUtils.xsl
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/UNIMARCslimUtils.xsl
@@ -460,19 +460,37 @@
   <xsl:template name="tag_subject">
     <xsl:param name="tag" />
     <xsl:param name="label" />
-    <xsl:param name="spanclass" />
+    <xsl:param name="spanclass"/>
     <xsl:if test="marc:datafield[@tag=$tag]">
       <span class="results_summary subjects {$spanclass}">
         <span class="label">
           <xsl:value-of select="$label"/>
           <xsl:text>: </xsl:text>
         </span>
-        <span class="value">
-          <xsl:for-each select="marc:datafield[@tag=$tag]">
-            <xsl:call-template name="tag_onesubject">
+        <xsl:for-each select="marc:datafield[@tag=$tag]">
+          <a>
+            <xsl:choose>
+              <xsl:when test="marc:subfield[@code=9]">
+                <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=su:<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/></xsl:attribute>
+              </xsl:otherwise>
+            </xsl:choose>
+            <xsl:call-template name="chopPunctuation">
+              <xsl:with-param name="chopString">
+                <xsl:call-template name="subfieldSelect">
+                    <xsl:with-param name="codes">abcdjptvxyz</xsl:with-param>
+                    <xsl:with-param name="subdivCodes">jpxyz</xsl:with-param>
+                    <xsl:with-param name="subdivDelimiter">-- </xsl:with-param>
+                </xsl:call-template>
+              </xsl:with-param>
             </xsl:call-template>
-          </xsl:for-each>
-        </span>
+          </a>
+          <xsl:if test="not (position()=last())">
+            <xsl:text> | </xsl:text>
+          </xsl:if>
+        </xsl:for-each>
       </span>
     </xsl:if>
   </xsl:template>
-- 
2.20.1