[Koha-devel] XSLT to display keywords with 650$2 = x
Andreas Roussos
a.roussos at dataly.gr
Tue Mar 2 15:17:30 CET 2021
Hi Magnus,
Give the following a try:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8" indent="no"/>
<xsl:template match="marc:record">
<xsl:if test="marc:datafield[starts-with(@tag,'65')]">
<xsl:for-each select="marc:datafield[starts-with(@tag,'65')]">
<xsl:if test="@tag=650">
<xsl:for-each select="marc:subfield">
<xsl:choose>
<xsl:when test="@code='2'">
<xsl:variable name="twoval" select="."/>
<xsl:if test="($twoval='x') or ($twoval='y')">
<xsl:value-of select="preceding-sibling::*[@code='a']"/>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:if>
<xsl:if test="@tag!=650">
<xsl:for-each select="marc:subfield">
<xsl:choose>
<xsl:when test="@code='a'">
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Regards,
Andreas
P.S.: There's probably a much better way of doing this... ;-)
On 2021-03-02 14:22, Magnus Enger wrote:
> Kia ora!
>
> I want to display most keywords as usual, but with an exception for
> those from the 650 field. Specifically, I want to display only those
> keywords that has the value "x" or "y" in subfield $2, and hide the
> other 650-keywords. Any hints on how to this in XSLT would be infinitely
> appreciated, and added to the wiki, so others can benefit from the
> solution.
>
> Here is an example:
>
> <datafield tag="650" ind1=" " ind2="0">
> <subfield code="a">A</subfield>
> <subfield code="2">x</subfield>
> </datafield>
> <datafield tag="650" ind1=" " ind2="0">
> <subfield code="a">B</subfield>
> <subfield code="2">y</subfield>
> </datafield>
> <datafield tag="650" ind1=" " ind2="0">
> <subfield code="a">C</subfield>
> <subfield code="2">z</subfield>
> </datafield>
> <datafield tag="653" ind1=" " ind2="0">
> <subfield code="a">D</subfield>
> </datafield>
>
> I want to display A and B (because they have $2 = x or y), and D
> (because it is not 650), but not C (because it is 650 and $2 is neither
> x nor y).
>
> Best regards,
> Magnus
> Libriotech
> _______________________________________________
> Koha-devel mailing list
> Koha-devel at lists.koha-community.org
> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
> website : https://www.koha-community.org/
> git : https://git.koha-community.org/
> bugs : https://bugs.koha-community.org/
More information about the Koha-devel
mailing list