[Koha] XSLT question

Paul Hoffman paul at flo.org
Thu Dec 6 10:06:54 NZDT 2018


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.

-- 
Paul Hoffman <paul at flo.org>
Software Services Manager
Fenway Library Organization
550 Huntington Ave.
Boston, MA 02115
(617) 442-2384


More information about the Koha mailing list