Bug 35305: Add XSLT for authority details page in staff interface

This adds a new system preference 'AuthorityXSLTDetailsDisplay'.
If set, authority MARCXML will be transformed using the XSLT
at the given filename or URL.
The HTML output will be displayed in place of tabs in details page.

The syspref value can contain {langcode} and {authtypecode} which will
be replaced by the appropriate value (resp. current language and
authority type code).

Test plan:
1) Apply patch and run updatedatabase
2) Search for an authority type GEOGR_NAME and view details page
3) Verify that display is not affected yet
4) Create an XSLT file (for example in /home/koha/xslt/en/GEOGR_NAME.xsl)
5) Set 'AuthorityXSLTDetailsDisplay' system preference to :
   /home/koha/xslt/{langcode}/{authtypecode}.xsl
6) Refresh details page
7) Verify that display matches what you expect from the XSLT
8) Set 'AuthorityXSLTDetailsDisplay' system preference to :
   <path to sources>/koha-tmpl/intranet-tmpl/prog/en/xslt/UNIMARCauthDetails.xsl
8) Refresh details page
9) Verify that display matches what you expect from your XSLT

Example of a minimal XSLT:

<?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 omit-xml-declaration="yes"/>
  <xsl:template match="marc:record">
    <xsl:element name="div">
      <xsl:attribute name="class">
        <xsl:text>authority-summary</xsl:text>
      </xsl:attribute>
      <xsl:value-of select="marc:datafield[@tag='151']/marc:subfield[@code='a']"/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Fridolin Somers 2023-11-09 11:20:43 -10:00 committed by Katrin Fischer
parent c2cc6869dd
commit dec81e0968
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
5 changed files with 50 additions and 4 deletions

View File

@ -38,16 +38,19 @@ parameters tables.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth qw( get_template_and_user );
use C4::AuthoritiesMarc qw( GetAuthority GenerateHierarchy GetTagsLabels );
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
use CGI qw ( -utf8 );
use C4::Koha;
use Koha::Authorities;
use C4::Languages;
use C4::Output qw( output_html_with_http_headers );
use Koha::Authorities;
use Koha::Authority::Types;
use Koha::Token;
use Koha::XSLT::Base;
use Koha::Z3950Servers;
our ($tagslib);
@ -213,7 +216,24 @@ while (my ($tagfield) = $sth->fetchrow) {
}
chop $biblio_fields if $biblio_fields;
build_tabs ($template, $record, $dbh,"",$query);
my $AuthorityXSLTDetailsDisplay = C4::Context->preference('AuthorityXSLTDetailsDisplay');
if ( $AuthorityXSLTDetailsDisplay ) {
my $xsl = $AuthorityXSLTDetailsDisplay;
my $lang = C4::Languages::getlanguage();
$xsl =~ s/\{langcode\}/$lang/g;
$xsl =~ s/\{authtypecode\}/$authtypecode/g;
my $xslt_engine = Koha::XSLT::Base->new;
my $output = $xslt_engine->transform({ xml => $authobj->marcxml, file => $xsl });
if ($xslt_engine->err) {
warn "XSL transformation failed ($xsl): " . $xslt_engine->err;
next;
}
$template->param( html => $output );
} else {
build_tabs ($template, $record, $dbh,"",$query);
}
my $servers = Koha::Z3950Servers->search(
{

View File

@ -0,0 +1,15 @@
use Modern::Perl;
return {
bug_number => "35305",
description => "Add XSLT for authority details display in staff interface",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
$dbh->do(q{
INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
VALUES ('AuthorityXSLTDetailsDisplay','','','Enable XSL stylesheet control over authority details page display on intranet','Free')
});
say $out "Added new system preference 'AuthorityXSLTDetailsDisplay'";
},
};

View File

@ -79,6 +79,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('AuthoritySeparator','--','10','Used to separate a list of authorities in a display. Usually --','free'),
('AuthorityXSLTOpacDetailsDisplay','','','Enable XSL stylesheet control over authority details page in the OPAC','Free'),
('AuthorityXSLTOpacResultsDisplay','','','Enable XSL stylesheet control over authority results page in the OPAC','Free'),
('AuthorityXSLTDetailsDisplay','','','Enable XSL stylesheet control over authority details page display on intranet','Free'),
('AuthorityXSLTResultsDisplay','','','Enable XSL stylesheet control over authority results page display on intranet','Free'),
('AuthorLinkSortBy','default','call_number|pubdate|acqdate|title','Specify the default field used for sorting when click author links','Choice'),
('AuthorLinkSortOrder','asc','asc|dsc|az|za','Specify the default sort order for author links','Choice'),

View File

@ -5,6 +5,11 @@ Staff interface:
- pref: AuthorityXSLTResultsDisplay
class: file
- '<br />Options:<ul><li>Put a path to define a xslt file</li><li>Put an URL for an external specific stylesheet.</li></ul>{langcode} will be replaced with current interface language and {authtypecode} will be replaced by the authority type code'
-
- 'Display authority details in the staff interface using XSLT stylesheet at: '
- pref: AuthorityXSLTDetailsDisplay
class: file
- '<br />Options:<ul><li>Put a path to define a xslt file</li><li>Put an URL for an external specific stylesheet.</li></ul>{langcode} will be replaced with current interface language and {authtypecode} will be replaced by the authority type code'
-
- "Display language selector on "
- pref: StaffLangSelectorMode

View File

@ -75,6 +75,10 @@
[% END %]
</div>
[% IF html %]
[% html | $raw %]
[% ELSE %]
[% WRAPPER tabs id= "authoritiestabs" %]
[% WRAPPER tabs_nav %]
[% FOREACH BIG_LOO IN BIG_LOOP %]
@ -128,6 +132,7 @@
[% END # /FOREACH BIG_LOO %]
[% END # /WRAPPER tab_panels %]
[% END # /WRAPPER tabs %]
[% END # /IF html %]
[% END # /IF ( unknownauthid ) %]
</div> <!-- /.col-md-8 offset-md-2 -->