Bug 18540: Handle indexing sort title only when needed

This patch moves the code that generates the xsl for MARC21 biblio sorting
to it's own template that is only called when specified in the xml

To test:
 1 - xsltproc etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml > etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
 2 - git diff
 3 - Note that authority-zebra-indexdefs.xsl now has 245 Title:s info
 4 - Apply patch
 5 - xsltproc etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml > etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
 6 - git diff
 7 - There are lines added about title sort, but no 245 block
 8 - xsltproc etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl etc/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml > etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl
 9 - git diff
10 - Note lines changes to ...title_sort
11 - 245 block does not change

Signed-off-by: Hayley Pelham <hayleypelham@catalyst.net.nz>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Nick Clemens 2021-05-13 16:34:38 +00:00 committed by Fridolin Somers
parent eb2136cfcc
commit 78d403ca3d
2 changed files with 32 additions and 13 deletions

View File

@ -397,6 +397,9 @@
<target_index>Title-collective:w</target_index>
</index_data_field>
<!--record.abs line 113: melm 245$a Title-cover:w,Title-cover:p,Title-cover:s,Title:w,Title:p,Title:s-->
<index_sort_title tag="245" subfields="a">
<target_index>Title:s</target_index>
</index_sort_title>
<index_subfields tag="245" subfields="a">
<target_index>Title-cover:w</target_index>
<target_index>Title-cover:p</target_index>

View File

@ -19,6 +19,7 @@
<xsl:key name="index_data_field_tag" match="kohaidx:index_data_field" use="@tag"/>
<xsl:key name="index_heading_conditional_tag" match="kohaidx:index_heading_conditional" use="@tag"/>
<xsl:key name="index_match_heading_tag" match="kohaidx:index_match_heading" use="@tag"/>
<xsl:key name="index_sort_title_tag" match="kohaidx:index_sort_title" use="@tag"/>
<xsl:template match="kohaidx:index_defs">
<xsl:comment>
@ -39,7 +40,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:template match="text()" mode="index_heading_conditional"/>
<xslo:template match="text()" mode="index_match_heading"/>
<xslo:template match="text()" mode="index_subject_thesaurus"/>
<xslo:template match="text()" mode="index_sort_tit"/>
<xslo:template match="text()" mode="index_sort_title"/>
<xslo:template match="/">
<xslo:if test="marc:collection">
<collection>
@ -66,7 +67,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:apply-templates mode="index_match_heading"/>
<xslo:apply-templates mode="index_subject_thesaurus"/>
<xslo:apply-templates mode="index_all"/>
<xslo:apply-templates mode="index_sort_tit"/>
<xslo:apply-templates mode="index_sort_title"/>
</z:record>
</xslo:template>
@ -78,23 +79,13 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xsl:call-template name="handle-index-heading"/>
<xsl:call-template name="handle-index-heading-conditional"/>
<xsl:call-template name="handle-index-match-heading"/>
<xsl:call-template name="handle-index-sort-title"/>
<xsl:apply-templates/>
<xslo:template mode="index_all" match="text()">
<z:index name="Any:w Any:p">
<xslo:value-of select="."/>
</z:index>
</xslo:template>
<xslo:template mode="index_sort_tit" match="marc:datafield[@tag='245']">
<xslo:variable name="chop">
<xslo:choose>
<xslo:when test="not(number(@ind2))">0</xslo:when>
<xslo:otherwise><xslo:value-of select="number(@ind2)"/></xslo:otherwise>
</xslo:choose>
</xslo:variable>
<z:index name="Title:s">
<xslo:value-of select="substring(marc:subfield[@code='a'], $chop+1)"/>
</z:index>
</xslo:template>
<xslo:template name="chopPunctuation">
<xslo:param name="chopString"/>
<xslo:variable name="length" select="string-length($chopString)"/>
@ -450,6 +441,31 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
</z:index>
</xsl:template>
<xsl:template name="handle-index-sort-title">
<xsl:for-each select="//kohaidx:index_sort_title[generate-id() = generate-id(key('index_sort_title_tag', @tag)[1])]">
<xslo:template mode="index_sort_title">
<xsl:attribute name="match">
<xsl:text>marc:datafield[@tag='</xsl:text>
<xsl:value-of select="@tag"/>
<xsl:text>']</xsl:text>
</xsl:attribute>
<xsl:for-each select="key('index_sort_title_tag', @tag)">
<xslo:variable name="chop">
<xslo:choose>
<xslo:when test="not(number(@ind2))">0</xslo:when>
<xslo:otherwise>
<xslo:value-of select="number(@ind2)"/>
</xslo:otherwise>
</xslo:choose>
</xslo:variable>
<z:index name="Title:s">
<xslo:value-of select="substring(marc:subfield[@code='a'], $chop+1)"/>
</z:index>
</xsl:for-each>
</xslo:template>
</xsl:for-each>
</xsl:template>
<xsl:template name="handle-index-match-heading">
<xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
<xslo:template mode="index_match_heading">