From b0013b11fe7081ee9da5d07740f9ea972c8d2b7e 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
Content-Type: text/plain; charset=utf-8

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
Signed-off-by: David Nind <david@davidnind.com>

Bug 29539: (follow-up) remove tag_onesubject template

Also:
Restores the <span class="value">
Replaces "not(position()=last())" with the more used "position() != last()"
Removes unecessary change in <xsl:param name="spanclass" />

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 .../bootstrap/en/xslt/UNIMARCslimUtils.xsl    | 107 ++++--------------
 1 file changed, 22 insertions(+), 85 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..af643df958 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/UNIMARCslimUtils.xsl
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/xslt/UNIMARCslimUtils.xsl
@@ -374,89 +374,6 @@
     </xsl:for-each>
   </xsl:template>
 
-  <xsl:template name="tag_onesubject">
-    <xsl:choose>
-      <xsl:when test="marc:subfield[@code=9]">
-        <xsl:for-each select="marc:subfield">
-          <xsl:if test="@code='9'">
-            <xsl:variable name="start" select="position()"/>
-            <xsl:variable name="ends">
-              <xsl:for-each select="../marc:subfield[position() &gt; $start]">
-                <xsl:if test="@code=9">
-                  <xsl:variable name="end" select="position() + $start"/>
-                  <xsl:value-of select="$end"/>
-                  <xsl:text>,</xsl:text>
-                </xsl:if>
-              </xsl:for-each>
-            </xsl:variable>
-            <xsl:variable name="end">
-              <xsl:choose>
-                <xsl:when test="string-length($ends) > 0">
-                  <xsl:value-of select="substring-before($ends,',')"/>
-                </xsl:when>
-                <xsl:otherwise>
-                  <xsl:text>1000</xsl:text>
-                </xsl:otherwise>
-              </xsl:choose>
-            </xsl:variable>
-            <xsl:variable name="display">
-              <xsl:for-each select="../marc:subfield[position() &gt; $start and position() &lt; $end and @code!=2 and @code!=3]">
-                <xsl:value-of select="."/>
-                <xsl:if test="not(position()=last())">
-                  <xsl:text>, </xsl:text>
-                </xsl:if>
-              </xsl:for-each>
-            </xsl:variable>
-            <a>
-              <xsl:attribute name="href">
-                <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
-                <xsl:value-of select="str:encode-uri(., true())"/>
-              </xsl:attribute>
-              <xsl:choose>
-                <xsl:when test="string-length($display) &gt; 0">
-                  <xsl:call-template name="chopPunctuation">
-                    <xsl:with-param name="chopString">
-                      <xsl:value-of select="$display"/>
-                    </xsl:with-param>
-                  </xsl:call-template>
-                </xsl:when>
-                <xsl:otherwise>
-                  <xsl:value-of select="."/>
-                </xsl:otherwise>
-              </xsl:choose>
-            </a>
-            <xsl:variable name="ncommas"
-                 select="string-length($ends) - string-length(translate($ends, ',', ''))" />
-            <xsl:if test="$ncommas &gt; 1">
-              <xsl:text> -- </xsl:text>
-            </xsl:if>
-          </xsl:if>
-        </xsl:for-each>
-      </xsl:when>
-      <xsl:when test="marc:subfield[@code='a']">
-        <a>
-          <xsl:attribute name="href">
-            <xsl:text>/cgi-bin/koha/opac-search.pl?q=su:</xsl:text>
-            <xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>
-          </xsl:attribute>
-          <xsl:call-template name="chopPunctuation">
-            <xsl:with-param name="chopString">
-              <xsl:call-template name="subfieldSelect">
-                <xsl:with-param name="codes">abcdfijkmnptvxyz</xsl:with-param>
-                <xsl:with-param name="subdivCodes">ijknpxyz</xsl:with-param>
-                <xsl:with-param name="subdivDelimiter">-- </xsl:with-param>
-              </xsl:call-template>
-            </xsl:with-param>
-          </xsl:call-template>
-        </a>
-      </xsl:when>
-      <xsl:otherwise/>
-    </xsl:choose>
-    <xsl:if test="not(position()=last())">
-      <xsl:text> | </xsl:text>
-    </xsl:if>
-  </xsl:template>
-
   <xsl:template name="tag_subject">
     <xsl:param name="tag" />
     <xsl:param name="label" />
@@ -469,8 +386,28 @@
         </span>
         <span class="value">
           <xsl:for-each select="marc:datafield[@tag=$tag]">
-            <xsl:call-template name="tag_onesubject">
-            </xsl:call-template>
+            <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>
+            </a>
+            <xsl:if test="position() != last()">
+              <xsl:text> | </xsl:text>
+            </xsl:if>
           </xsl:for-each>
         </span>
       </span>
-- 
2.30.2