[librecat-dev] Merge multiple MARC fields into one

Patrick Hochstenbach Patrick.Hochstenbach at UGent.be
Tue Jun 27 08:51:50 CEST 2023


Indeed, this is a bit nasty example but it can be fixed with a nasty trick.

You can use the fact that internally, for Catmandu, a MARC record is nothing more than `record` field which contains an array-of-an-array values.

With the fix below you can create a new field (in the array form Catmandu needs) and add it to the `record` field:


if marc_has(776)
    marc_map('776z',tmp.$append)

    # Marc field
    add_field(zz.$append,999)
    # Ind1 & 2
    add_field(zz.$append,0)
    add_field(zz.$append,8)
    # $i
    add_field(zz.$append,i)
    add_field(zz.$append,'Erscheint auch als')
    # $n
    add_field(zz.$append,n)
    add_field(zz.$append,'Druck-Ausgabe')
    # All the $z
    do list(path:tmp,var:z)
        add_field(zz.$append,z)
        copy_field(z,zz.$append)
    end
    # Add this new field to the record
    move_field(zz,record.$append)
end

remove_field(tmp)

Cheers
Patrick

From: librecat-dev-bounces at lists.uni-bielefeld.de <librecat-dev-bounces at lists.uni-bielefeld.de> on behalf of Mayr-Duffner, Georg <georg.mayr-duffner at wu.ac.at>
Date: Thursday, 22 June 2023 at 10:43
To: librecat-dev at lists.uni-bielefeld.de <librecat-dev at lists.uni-bielefeld.de>
Subject: [librecat-dev] Merge multiple MARC fields into one
Hi,

I’m trying to combine two MARC fields into one with Catmandu and somehow it doesn’t come along as expected.

The MARC record has two fields 776:
776 08 $z 9876543210111
776 08 $z 9876543210112

These should be combined into one 776 with two subfields prepended:

776 08 $i Erscheint auch als $n Druck-Ausgabe $z 9876543210111 $z 9876543210112

I tried various approaches without success. The closest I got was:

```
if marc_has('776')
    marc_add('999', ind1, '0', ind2, '8', i, 'Erscheint auch als', n, 'Druck-Ausgabe')
    marc_cut('999', tmp776)
    do marc_each()
        if marc_has('776z')
            marc_map('776z', tmpisbn)
            add_field(tmp776.*.subfields.$append.z,$.tmpisbn)
            marc_remove('776')
        end
    end
    set_field(tmp776.*.tag,776)
    marc_paste(tmp776)
end
```

But this interprets `$.tmpisbn` as a string instead of a variable and inserts it lterally.

How could I fix this?

Thanks!

Kind regards,
Georg


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20230627/455d4818/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: georg.zip
Type: application/zip
Size: 891 bytes
Desc: georg.zip
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20230627/455d4818/attachment.zip>


More information about the librecat-dev mailing list