Bug 40972

Summary: New hook: extend Marc Filter
Product: Koha Reporter: Alexander Wagner <alexander.wagner>
Component: Plugin architectureAssignee: Bugs List <koha-bugs>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: dcook, mark, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: Sponsored Comma delimited list of Sponsors: Naturhistorisches Museum Wien
Crowdfunding goal: 0 Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 40972: Add XSLT record processor filter hook for plugins
Bug 40972: Add XSLT record processor filter hook for plugins

Description Alexander Wagner 2025-10-08 11:37:57 UTC
Koha allows to add filters that massage the Marc record before it is passed on to the processing routines. The relevant section in C4::XLST.pm reads

```perl

    my $record_processor = Koha::RecordProcessor->new(
        {
            filters => ['ExpandCodedFields'],
            options => {
                interface     => $interface,
                frameworkcode => $frameworkcode
            }
        }
    );

```

Unfortunately, there seems easily accessible way to extend the `filters` array so it is currently not possible to eg. hook up a plugin to add a filter in this position.

To help proceeding on bugs 21303, 30018, 37296, 37325 it would be helpful to have a hook here so development of the automatic punctuation could first be done as a plugin.
Comment 1 David Cook 2025-10-08 23:41:48 UTC
Off the top of my head, I might be a bit worried about this from a performance perspective, but it's interesting.
Comment 2 Alexander Wagner 2025-10-13 07:21:47 UTC
So your fear is that the perl processing step is way slower then the XSLT or do you fear that adding the chars on the fly is a general issue?

(BTW: the processing would be cut short for fields that hold punctuation.)
Comment 3 David Cook 2025-10-13 23:54:45 UTC
(In reply to Alexander Wagner from comment #2)
> So your fear is that the perl processing step is way slower then the XSLT or
> do you fear that adding the chars on the fly is a general issue?

Just any time we add more code for something in a loop, it's going to slow down, so just thinking about scalability.
Comment 4 Mark Hofstetter 2026-02-06 10:55:59 UTC
several customers/user have expressed interest in this issue, so I'm looking into it

I don't see the performance issues as grave, but have to kept in mind
Comment 5 Mark Hofstetter 2026-02-06 11:27:11 UTC
Created attachment 192611 [details] [review]
Bug 40972: Add XSLT record processor filter hook for plugins

Koha's XSLT display path now calls a plugin hook so plugins can
extend the record processor filter list before MARC is transformed.
This enables prototype punctuation filters (and similar) to run
as plugins without core changes.

Test plan:
1) Enable plugins in koha-conf.xml.
2) Install the TestPunctuation plugin from https://github.com/HKS3/koha-test-punctuation
3) Enable the plugin in Koha admin.
4) View a biblio in staff or OPAC with XSLT display enabled and confirm
   the filter runs (e.g., 245$a gets a trailing period if missing).
Comment 6 Alexander Wagner 2026-02-06 14:32:57 UTC
AFAIS from my first tests this does the trick and allows the test-plugin to act accordingly. I could start migrating the filter code that exists already for the plugin.
Comment 7 Alexander Wagner 2026-02-06 14:37:17 UTC
WRT the performance issues mentioned, I wonder if it was ever discussed to cache (some of) the calculated output formats. Calculating e.g. the brief display for the search results list upon record change would probably have the most impact, while calculating the details page on the fly should always be fast enough these days. (At least this is the experience we have on our current, non-koha system. Said system has indeed some quite clever handling on this end, but implementing it in full glory would be a major change to Kohas processing.)
Comment 8 Alexander Wagner 2026-02-10 14:06:52 UTC
Created attachment 192901 [details] [review]
Bug 40972: Add XSLT record processor filter hook for plugins

Koha's XSLT display path now calls a plugin hook so plugins can
extend the record processor filter list before MARC is transformed.
This enables prototype punctuation filters (and similar) to run
as plugins without core changes.

Test plan:
1) Enable plugins in koha-conf.xml.
2) Install the TestPunctuation plugin from https://github.com/HKS3/koha-test-punctuation
3) Enable the plugin in Koha admin.
4) View a biblio in staff or OPAC with XSLT display enabled and confirm
   the filter runs (e.g., 245$a gets a trailing period if missing).

Signed-off-by: Alexander Wagner <alexander.wagner@desy.de>
Comment 9 Katrin Fischer 2026-02-10 19:38:08 UTC
Hi Alexander, did you mean to set this to Signed off?
Comment 10 Alexander Wagner 2026-02-11 08:54:53 UTC
I was unsure if a bug propagates from "on discussion" by one sign off right to `singed off` or if it requires a second sign off. But in principle it works in my test according to Marks plan as designed. I even changed the code I use for j2k to integrate with Marks plugin.