Bug 31106: Fix links generated in XSLTs

This patch addresses the case of links that are generated on the XSLT
side, those linking to and from host records using 773$t and 773$a.

To test:
1. Pick a bibliographic record (I chose 'Unconditional' from the sample
   data
2. Add " and ? to the title statement. I changed it to
   'Uncond"itional?¿'
3. Add a child record to it
4. Open the detail page for the host record
=> FAIL: It doesn't show the 'Show analytics' link
5. Repeat 4 for the same record, in the OPAC
=> FAIL: It doesn't show the 'Show analytics' link
6. Apply this patch
7. Repeat 4 and 5.
=> SUCCESS: Links are shown!
8. Follow the links
=> SUCCESS: The links take you to the right resultset!
9. Go to the child record, and notice the link back to the parent works
   :-D
10. Sign off :-D

Sponsored-by: Theke Solutions
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2022-07-04 21:09:05 -03:00
parent 24bb15785d
commit e1b63d9df3
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 110 additions and 4 deletions

View file

@ -215,7 +215,14 @@
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=rcn:<xsl:value-of select="str:encode-uri(marc:controlfield[@tag=001], true())"/>+AND+(bib-level:a+OR+bib-level:b)</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Host-item:(<xsl:value-of select="str:encode-uri(translate(marc:datafield[@tag=245]/marc:subfield[@code='a'], '/', ''), true())"/>)</xsl:attribute>
<xsl:variable name="title_query">
<xsl:text>Host-item:(</xsl:text>
<xsl:call-template name="quote_search_term">
<xsl:with-param name="term"><xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='a']"/></xsl:with-param>
</xsl:call-template>
<xsl:text>)</xsl:text>
</xsl:variable>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=<xsl:value-of select="str:encode-uri($title_query, true())"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:text>Show analytics</xsl:text>
@ -1083,8 +1090,25 @@
</a>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="host_query">
<xsl:text>ti,phr:(</xsl:text>
<xsl:call-template name="quote_search_term">
<xsl:with-param name="term"><xsl:value-of select="marc:subfield[@code='t']"/></xsl:with-param>
</xsl:call-template>
<xsl:text>)</xsl:text>
<xsl:if test="marc:subfield[@code='a']">
<xsl:text> AND au:(</xsl:text>
<xsl:call-template name="quote_search_term">
<xsl:with-param name="term">
<xsl:value-of select="marc:subfield[@code='a']"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:variable>
<a>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=ti,phr:<xsl:value-of select="str:encode-uri(translate(marc:subfield[@code='t'], '()', ''), true())"/><xsl:if test="marc:subfield[@code='a']">+AND+au:<xsl:value-of select="str:encode-uri(translate(marc:subfield[@code='a'], '()', ''), true())"/></xsl:if></xsl:attribute>
<xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=<xsl:value-of select="str:encode-uri($host_query, true())" />
</xsl:attribute>
<xsl:value-of select="$f773"/>
</a>
</xsl:otherwise>

View file

@ -578,6 +578,35 @@
</xsl:if>
</xsl:template>
<xsl:template name="quote_search_term">
<xsl:param name="term" />
<xsl:text>"</xsl:text>
<xsl:call-template name="escape_quotes">
<xsl:with-param name="text">
<xsl:value-of select="$term"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template name="escape_quotes">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '&quot;')">
<xsl:variable name="before" select="substring-before($text,'&quot;')"/>
<xsl:variable name="next" select="substring-after($text,'&quot;')"/>
<xsl:value-of select="$before"/>
<xsl:text>\&quot;</xsl:text>
<xsl:call-template name="escape_quotes">
<xsl:with-param name="text" select="$next"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.

View file

@ -257,7 +257,14 @@
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=rcn:<xsl:value-of select="str:encode-uri(marc:controlfield[@tag=001], true())"/>+AND+(bib-level:a+OR+bib-level:b)</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=Host-item:(<xsl:value-of select="str:encode-uri(translate(marc:datafield[@tag=245]/marc:subfield[@code='a'], '/', ''), true())"/>)</xsl:attribute>
<xsl:variable name="title_query">
<xsl:text>Host-item:(</xsl:text>
<xsl:call-template name="quote_search_term">
<xsl:with-param name="term"><xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='a']"/></xsl:with-param>
</xsl:call-template>
<xsl:text>)</xsl:text>
</xsl:variable>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of select="str:encode-uri($title_query, true())"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:text>Show analytics</xsl:text>
@ -1230,8 +1237,25 @@
</a>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="host_query">
<xsl:text>ti,phr:(</xsl:text>
<xsl:call-template name="quote_search_term">
<xsl:with-param name="term"><xsl:value-of select="marc:subfield[@code='t']"/></xsl:with-param>
</xsl:call-template>
<xsl:text>)</xsl:text>
<xsl:if test="marc:subfield[@code='a']">
<xsl:text> AND au:(</xsl:text>
<xsl:call-template name="quote_search_term">
<xsl:with-param name="term">
<xsl:value-of select="marc:subfield[@code='a']"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:variable>
<a>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=ti,phr:<xsl:value-of select="str:encode-uri(translate(marc:subfield[@code='t'], '()', ''), true())"/><xsl:if test="marc:subfield[@code='a']">+AND+au:<xsl:value-of select="str:encode-uri(translate(marc:subfield[@code='a'], '()', ''), true())"/></xsl:if></xsl:attribute>
<xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of select="str:encode-uri($host_query, true())" />
</xsl:attribute>
<xsl:value-of select="$f773"/>
</a>
</xsl:otherwise>

View file

@ -542,6 +542,35 @@
</xsl:if>
</xsl:template>
<xsl:template name="quote_search_term">
<xsl:param name="term" />
<xsl:text>"</xsl:text>
<xsl:call-template name="escape_quotes">
<xsl:with-param name="text">
<xsl:value-of select="$term"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>"</xsl:text>
</xsl:template>
<xsl:template name="escape_quotes">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '&quot;')">
<xsl:variable name="before" select="substring-before($text,'&quot;')"/>
<xsl:variable name="next" select="substring-after($text,'&quot;')"/>
<xsl:value-of select="$before"/>
<xsl:text>\&quot;</xsl:text>
<xsl:call-template name="escape_quotes">
<xsl:with-param name="text" select="$next"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.