Bug 27101: Fix sample_notices.t
[srvgit] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / NORMARCslimUtils.xsl
index 7007d96..ec9358e 100644 (file)
@@ -1,6 +1,10 @@
 <?xml version='1.0'?>
-<!DOCTYPE stylesheet [<!ENTITY nbsp "&#160;" >]>
-<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<!DOCTYPE stylesheet>
+<xsl:stylesheet version="1.0"
+  xmlns:marc="http://www.loc.gov/MARC21/slim"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:str="http://exslt.org/strings"
+  exclude-result-prefixes="str">
        <xsl:template name="datafield">
                <xsl:param name="tag"/>
                <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
@@ -27,6 +31,7 @@
                <xsl:param name="subdivDelimiter"/>
         <xsl:param name="prefix"/>
         <xsl:param name="suffix"/>
+        <xsl:param name="urlencode"/>
                <xsl:variable name="str">
                        <xsl:for-each select="marc:subfield">
                                <xsl:if test="contains($codes, @code)">
                                </xsl:if>
                        </xsl:for-each>
                </xsl:variable>
-               <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+        <xsl:choose>
+            <xsl:when test="$urlencode=1">
+                <xsl:value-of select="str:encode-uri(substring($str,1,string-length($str)-string-length($delimeter)), true())"/>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+            </xsl:otherwise>
+        </xsl:choose>
        </xsl:template>
 
        <xsl:template name="buildSpaces">
                </xsl:if>
        </xsl:template>
 
-    <xsl:template name="buildBiblioDefaultViewURL">
-      <xsl:param name="BiblioDefaultView"/>
-      <xsl:choose>
-          <xsl:when test="$BiblioDefaultView='normal'">
-              <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
-          </xsl:when>
-          <xsl:when test="$BiblioDefaultView='isbd'">
-              <xsl:text>/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=</xsl:text>
-          </xsl:when>
-          <xsl:when test="$BiblioDefaultView='labeled_marc'">
-              <xsl:text>/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=</xsl:text>
-          </xsl:when>
-          <xsl:when test="$BiblioDefaultView='marc'">
-              <xsl:text>/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=</xsl:text>
-          </xsl:when>
-          <xsl:otherwise>
-              <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
-          </xsl:otherwise>
-      </xsl:choose>
-    </xsl:template>
+  <xsl:template name="buildBiblioDefaultViewURL">
+    <xsl:param name="BiblioDefaultView"/>
+    <xsl:choose>
+        <xsl:when test="$BiblioDefaultView='normal'">
+            <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
+        </xsl:when>
+        <xsl:when test="$BiblioDefaultView='isbd'">
+            <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
+        </xsl:when>
+        <xsl:when test="$BiblioDefaultView='marc'">
+            <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
+        </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
 
        <xsl:template name="chopPunctuation">
                <xsl:param name="chopString"/>
             Assumes LOC convention: (OrgCode)recordNumber.
             If OrgCode is not present, return full string.
             Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
+         Returns the value URI-encoded.
        -->
        <xsl:template name="extractControlNumber">
            <xsl:param name="subfieldW"/>
            <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
            <xsl:choose>
              <xsl:when test="contains($tranW,')')">
-               <xsl:value-of select="normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;',''))"/>
+               <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
              </xsl:when>
              <xsl:otherwise>
-               <xsl:value-of select="normalize-space($subfieldW)"/>
+               <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
              </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
                         <xsl:choose>
                             <xsl:when test="boolean($bibno)">
                                 <a>
-                                    <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="$bibno"/></xsl:attribute>
+                                    <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
                                     <xsl:value-of select="$str"/>
                                 </a>
                             </xsl:when>
                            <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
                                 <a>
-                                    <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of  select="marc:subfield[@code=9]"/></xsl:attribute>
+                                    <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:value-of select="$str"/>
                                 </a>
                             </xsl:when>
                             <xsl:when test="boolean($index)">
                                 <a>
-                                    <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of  select="$index"/>:<xsl:value-of  select="marc:subfield[@code='a']"/></xsl:attribute>
+                                    <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of  select="$index"/>:<xsl:value-of  select="str:encode-uri(marc:subfield[@code='a'], true())"/></xsl:attribute>
                                     <xsl:value-of select="$str"/>
                                 </a>
                             </xsl:when>