[Koha] XSLT question
Michael Kuhn
mik at adminkuhn.ch
Thu Dec 6 13:21:03 NZDT 2018
Hi Paul
Am 05.12.18 um 22:06 schrieb Paul Hoffman:
> On Wed, Dec 05, 2018 at 09:18:35PM +0100, Michael Kuhn wrote:
>> I've got the following content in MARC 245:
>>
>> 245 00 _aTitle
>> _pPart
>> _nVolume
>>
>> I'm using the following XSL code in file "MARC21slim2OPACDetail.xsl":
>>
>> <xsl:if test="marc:datafield[@tag=245]">
>> <xsl:for-each select="marc:datafield[@tag=245]">
>> <xsl:call-template name="subfieldSelect">
>> <xsl:with-param name="codes">a</xsl:with-param>
>> </xsl:call-template>
>> <xsl:text></xsl:text>
>> <xsl:for-each select="marc:subfield[contains('np', @code)]">
>> <xsl:choose>
>> <xsl:when test="@code='n'">
>> <br/>
>> <span class="title_medium"><xsl:apply-templates/></span>
>> </xsl:when>
>> <xsl:when test="@code='p'">
>> <xsl:text> : </xsl:text><span
>> class="title_medium"><xsl:apply-templates/></span>
>> </xsl:when>
>> </xsl:choose>
>> </xsl:for-each>
>> </xsl:for-each>
>> </xsl:if>
>>
>> I'm expecting the following two lines:
>>
>> Title
>> Volume : Part
>>
>> But in fact I'm getting these lines:
>>
>> Title : Part
>> Volume
>>
>> It seems like I can't get 245$n to precede 245$p ... What am I doing wrong,
>> can please someone explain?
>
> You're doing this:
>
> if there's a 245 field:
> for each 245 field:
> print subfield $a
> for each subfield $n or $p:
> if it's $n:
> print "<br/>" followed by the subfield contents
> else if it's $p:
> print " : " followed by the subfield contents
> end
> end
> end
> end
>
> But that doesn't process 245$n before 245$p. So use the following
> logic, or something like it:
>
> for each 245 field:
> print subfield $a
> for each subfield $n:
> print "<br/>" followed by the subfield contents
> end
> for each subfield $p:
> print " : " followed by the subfield contents
> end
> end
>
> (The outer conditional seems unnecessary to me, but I could be wrong).
>
> Does that help?
>
> Paul.
>
Yes, it helped me a lot, thank you very much! After using XSL for some
hours I was slightly going nuts probably... but now I came up with the
following and it works as expected:
<xsl:if test="marc:datafield[@tag=245]">
<xsl:for-each select="marc:datafield[@tag=245]">
<xsl:call-template name="subfieldSelect">
<xsl:with-param name="codes">a</xsl:with-param>
</xsl:call-template>
<xsl:for-each select="marc:subfield[contains('n', @code)]">
<span class="title_medium"><br/><xsl:apply-templates/></span>
</xsl:for-each>
<xsl:for-each select="marc:subfield[contains('p', @code)]">
<span class="title_medium"><xsl:text> :
</xsl:text><xsl:apply-templates/></span>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
Well... in fact this was just the part about showing MARC 245 using the
original file "MARC21slim2OPACDetail.xsl" that didn't work as we wanted
it. I have now replaced that part with the new one.
Best wishes: Michael
--
Geschäftsführer · Diplombibliothekar BBS, Informatiker eidg. Fachausweis
Admin Kuhn GmbH · Pappelstrasse 20 · 4123 Allschwil · Schweiz
T 0041 (0)61 261 55 61 · E mik at adminkuhn.ch · W www.adminkuhn.ch
More information about the Koha
mailing list