@@ -, +, @@ test case: - Apply patch - Create folder /koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport for intranet - Create folder /koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport for opac - In the folder /koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport-samples, you found sample xslt - Copie this file in /koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport for intranet and in /koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport for opac. - Open intranet or opac interface and submit any search, open any notices found. - Click save and you found Simple Export. - Click Simple Export and you have a file.html, it contain informations returned by the xslt file. - It work correctly in basket and lists. - The name 'Simple Export' it's extract in the xslt file, curently the name is MARC21_simple_export.xsl. --- C4/XSLT.pm | 77 +++++++++++++++++++++- Koha/XSLT_Handler.pm | 1 - basket/basket.pl | 2 + basket/downloadcart.pl | 7 +- catalogue/detail.pl | 3 + catalogue/export.pl | 15 +++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 3 + .../prog/en/includes/virtualshelves-toolbar.inc | 3 + .../intranet-tmpl/prog/en/modules/basket/basket.tt | 3 + .../prog/en/modules/catalogue/detail.tt | 5 +- .../en/modules/virtualshelves/downloadshelf.tt | 3 + .../biblioexport-samples/MARC21_simple_export.xsl | 62 +++++++++++++++++ .../en/xslt/biblioexport/MARC21_simple_export.xsl | 62 +++++++++++++++++ .../intranet-tmpl/prog/en/xslt/biblioexport/README | 0 .../bootstrap/en/includes/opac-detail-sidebar.inc | 3 + .../bootstrap/en/modules/opac-downloadcart.tt | 3 + .../bootstrap/en/modules/opac-downloadshelf.tt | 3 + .../biblioexport-samples/MARC21_simple_export.xsl | 62 +++++++++++++++++ .../en/xslt/biblioexport/MARC21_simple_export.xsl | 62 +++++++++++++++++ .../bootstrap/en/xslt/biblioexport/README | 0 opac/opac-detail.pl | 3 + opac/opac-downloadcart.pl | 6 ++ opac/opac-export.pl | 11 +++- virtualshelves/downloadshelf.pl | 6 +- virtualshelves/shelves.pl | 1 + 25 files changed, 398 insertions(+), 8 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport-samples/MARC21_simple_export.xsl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/README create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport-samples/MARC21_simple_export.xsl create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/README --- a/C4/XSLT.pm +++ a/C4/XSLT.pm @@ -46,6 +46,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &XSLTParse4Display + &CustomXSLTExportList ); $engine=Koha::XSLT_Handler->new( { do_not_return_source => 1 } ); } @@ -186,13 +187,27 @@ sub get_xslt_sysprefs { } sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang ) = @_; + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $xslFile, $opac ) = @_; $sysxml ||= C4::Context->preference($xslsyspref); $xslfilename ||= C4::Context->preference($xslsyspref); $lang ||= C4::Languages::getlanguage(); - if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { + if ($xslFile) { + my $myDir; + if ($opac) { + $myDir = C4::Context->config('opachtdocs') . + '/' . C4::Context->preference("opacthemes") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + } else { + $myDir = C4::Context->config('intrahtdocs') . + '/' . C4::Context->preference("template") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + } + $xslfilename = $myDir."/".$xslFile; + }elsif( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my $htdocs; my $theme; my $xslfile; @@ -240,7 +255,6 @@ sub XSLTParse4Display { my $record = transformMARCXML4XSLT($biblionumber, $orig_record); my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); - $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; if ($fixamps) { # We need to correct the HTML entities that Zebra outputs $xmlrecord =~ s/\&amp;/\&/g; @@ -345,6 +359,63 @@ Returns reference to XSLT handler object. sub engine { return $engine; } +=head2 CustomXSLTExportList + + Returns list of file for custom xslt conversion + +=cut + +sub CustomXSLTExportList { + my $opac = shift; # opac (1) vs intranet (0) + my @tabFiles; + + my $myDir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') . + '/' . C4::Context->preference( $opac ? "opacthemes" : "template") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + my @files = <$myDir/*.xsl>; + foreach my $file (@files) { + if ( -f "$file" ) { + local $/ = undef; + open FILE, $file or die $!; + my @lines = split('\n', ); + close (FILE); + (my $text = $file) =~ s/.*\///g; + my $title = ""; + my $outputformat = ""; + ## Get title of the option + + foreach my $line (@lines){ + next unless $line =~ /xml/; + $line =~ /title="([\w\s]+)"/; + $title = $1; + + last if defined $title; + } + ($title = $text) =~ s/\.xsl// unless defined $title; + + ## Get output format + foreach my $line (@lines){ + next unless $line =~ /xsl:output/; + $line =~ /method="([\w\s]+)"/; + $outputformat = $1; + + last if defined $outputformat; + } + $outputformat = "txt" if ($outputformat eq "" || $outputformat eq "text"); + + my %row = ( + value => $text, + filename => $title, + format => $outputformat, + ); + + push @tabFiles, \%row; + } + } + return \@tabFiles; +} + 1; --- a/Koha/XSLT_Handler.pm +++ a/Koha/XSLT_Handler.pm @@ -165,7 +165,6 @@ sub transform { } else { ( $xml, $filename ) = @_; } - #Initialized yet? if ( !$self->{xslt_hash} ) { $self->_init; --- a/basket/basket.pl +++ a/basket/basket.pl @@ -23,6 +23,7 @@ use C4::Biblio; use C4::Items; use C4::Auth; use C4::Output; +use C4::XSLT; use Koha::CsvProfiles; @@ -122,6 +123,7 @@ my $resultsarray = \@results; $template->param( BIBLIO_RESULTS => $resultsarray, csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], + xsl_exports => CustomXSLTExportList(), bib_list => $bib_list, ); --- a/basket/downloadcart.pl +++ a/basket/downloadcart.pl @@ -28,7 +28,7 @@ use C4::Items; use C4::Output; use C4::Record; use C4::Ris; - +use C4::XSLT; use Koha::CsvProfiles; use utf8; @@ -77,11 +77,15 @@ if ($bib_list && $format) { elsif ($format eq 'bibtex') { $output .= marc2bibtex($record, $biblio); } + elsif ($format =~ /^xsl\.(.*)$/) { + $output .= XSLTParse4Display($biblio, $record, 'Results', 1, undef, , '', $1, '', $1 ); + } } } # If it was a CSV export we change the format after the export so the file extension is fine $format = "csv" if ($format =~ m/^\d+$/); + $format = "html" if ($format =~ /^xsl\./); print $query->header( -type => 'application/octet-stream', @@ -91,6 +95,7 @@ if ($bib_list && $format) { } else { $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ]); + $template->param(xsl_exports => CustomXSLTExportList()); $template->param(bib_list => $bib_list); output_html_with_http_headers $query, $cookie, $template->output; } --- a/catalogue/detail.pl +++ a/catalogue/detail.pl @@ -57,6 +57,9 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user( } ); +##### ADD CUSTOM XSLT +$template->param(filesOptions => CustomXSLTExportList(0)); + my $biblionumber = $query->param('biblionumber'); $biblionumber = HTML::Entities::encode($biblionumber); my $record = GetMarcBiblio($biblionumber); --- a/catalogue/export.pl +++ a/catalogue/export.pl @@ -8,6 +8,7 @@ use C4::Output; use C4::Biblio; use CGI qw ( -utf8 ); use C4::Ris; +use C4::XSLT; @@ -77,4 +78,18 @@ if ($op eq "export") { -attachment=>"bib-$biblionumber.$format"); print $marc; } +}elsif ($op eq "exportxsl"){ + my $biblionumber = $query->param("bib"); + if ($biblionumber){ + my $xslFile = $query->param("file"); + my $marc = GetMarcBiblio($biblionumber, 1); + my $format=$query->param("format")||'txt'; + my @hiddenitems; + + $marc = XSLTParse4Display($biblionumber, $marc, 'Results', 1, \@hiddenitems,'', $xslFile,'', $xslFile); + print $query->header( + -type => 'application/octet-stream', + -attachment=>"bib-$biblionumber.$format"); + print $marc; + } } --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -222,6 +222,9 @@ CAN_user_serials_create_subscription ) %]
  • MARC (Unicode/UTF-8, Standard)
  • MODS (XML)
  • RIS
  • + [% FOREACH filesOption IN filesOptions %] +
  • [% filesOption.filename %]
  • + [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc @@ -49,6 +49,9 @@ [% FOREACH csv_profile IN csv_profiles %]
  • CSV - [% csv_profile.profile %]
  • [% END %] + [% FOREACH xsl_export IN xsl_exports %] +
  • XSL - [% xsl_export.filename %]
  • + [% END %]
    Send list
    --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt @@ -61,6 +61,9 @@ [% FOREACH csv_profile IN csv_profiles %]
  • CSV - [% csv_profile.profile %]
  • [% END %] + [% FOREACH xsl_export IN xsl_exports %] +
  • XSL - [% xsl_export.filename %]
  • + [% END %] Print --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1094,7 +1094,10 @@ function verify_images() { - + + [% FOREACH filesOption IN filesOptions %] + + [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/downloadshelf.tt @@ -36,6 +36,9 @@ [% FOREACH csv_profile IN csv_profiles %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] + + [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport-samples/MARC21_simple_export.xsl +++ a/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport-samples/MARC21_simple_export.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + +

    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + +
    +

    +
    + +
    --- a/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl +++ a/koha-tmpl/intranet-tmpl/prog/en/xslt/biblioexport/MARC21_simple_export.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + +

    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + +
    +

    +
    + +
    --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -56,6 +56,9 @@ [% END %] [% END %] + [% FOREACH filesOption IN filesOptions %] +
  • [% filesOption.filename %]
  • + [% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadcart.tt @@ -20,6 +20,9 @@ [% FOREACH csv_profile IN csv_profiles %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] + + [% END %]
    --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-downloadshelf.tt @@ -59,6 +59,9 @@ [% FOREACH csv_profile IN csv_profiles %] [% END %] + [% FOREACH xsl_export IN xsl_exports %] + + [% END %] Required
    --- a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport-samples/MARC21_simple_export.xsl +++ a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport-samples/MARC21_simple_export.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + +

    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + +
    +

    +
    + +
    --- a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl +++ a/koha-tmpl/opac-tmpl/bootstrap/en/xslt/biblioexport/MARC21_simple_export.xsl @@ -0,0 +1,62 @@ + + + + + + + + + + +

    + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + +
    +

    +
    + +
    --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -69,6 +69,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); +##### ADD CUSTOM XSLT +$template->param(filesOptions => CustomXSLTExportList(1)); + my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0; $biblionumber = int($biblionumber); --- a/opac/opac-downloadcart.pl +++ a/opac/opac-downloadcart.pl @@ -28,6 +28,7 @@ use C4::Items; use C4::Output; use C4::Record; use C4::Ris; +use C4::XSLT; use Koha::CsvProfiles; use Koha::RecordProcessor; @@ -97,11 +98,15 @@ if ($bib_list && $format) { $extension = "txt"; $type = "text/plain"; } + elsif ($format =~ /^xsl\.(.*)$/) { + $output .= XSLTParse4Display($biblio, $record, 'Results', 1, undef, undef, undef, undef, $1, 1); + } } } # If it was a CSV export we change the format after the export so the file extension is fine $format = "csv" if ($format =~ m/^\d+$/); + $format = "html" if ($format =~ /^xsl\./); print $query->header( -type => ($type) ? $type : 'application/octet-stream', @@ -112,6 +117,7 @@ if ($bib_list && $format) { } else { $template->param(csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ]); + $template->param(xsl_exports => CustomXSLTExportList()); $template->param(bib_list => $bib_list); output_html_with_http_headers $query, $cookie, $template->output; } --- a/opac/opac-export.pl +++ a/opac/opac-export.pl @@ -26,6 +26,7 @@ use C4::Biblio; use CGI qw ( -utf8 ); use C4::Auth; use C4::Ris; +use C4::XSLT; use Koha::RecordProcessor; my $query = CGI->new; @@ -34,7 +35,6 @@ my $format=$query->param("format")||'utf8'; my $biblionumber = $query->param("bib")||0; $biblionumber = int($biblionumber); my $error = q{}; - my $include_items = ($format =~ /bibtex/) ? 0 : 1; my $marc = GetMarcBiblio($biblionumber, $include_items) if $biblionumber; @@ -103,6 +103,15 @@ elsif ( $format =~ /isbd/ ) { }); $format = 'isbd'; } +elsif ($format =~ /html/ ) { + if ($biblionumber){ + my $xslFile = $query->param("file"); + $marc = C4::Biblio::GetMarcBiblio($biblionumber); + my @hiddenitems; + + $marc = XSLTParse4Display($biblionumber, $marc, 'Results', 1, \@hiddenitems, undef, undef, undef, $xslFile, 1); + } +} else { $error= "Format $format is not supported."; } --- a/virtualshelves/downloadshelf.pl +++ a/virtualshelves/downloadshelf.pl @@ -28,6 +28,7 @@ use C4::Items; use C4::Output; use C4::Record; use C4::Ris; +use C4::XSLT; use Koha::CsvProfiles; use Koha::Virtualshelves; @@ -81,12 +82,15 @@ if ($shelfid && $format) { elsif ($format eq 'bibtex') { $output .= marc2bibtex($record, $biblionumber); } + elsif ($format =~ /^xsl\.(.*)$/){ + $output .= XSLTParse4Display($biblionumber, $record, 'Results', 1, undef, ,'',$1,'',$1); + } } } # If it was a CSV export we change the format after the export so the file extension is fine $format = "csv" if ($format =~ m/^\d+$/); - + $format = "html" if ($format =~ /^xsl\./); print $query->header( -type => 'application/octet-stream', -'Content-Transfer-Encoding' => 'binary', --- a/virtualshelves/shelves.pl +++ a/virtualshelves/shelves.pl @@ -312,6 +312,7 @@ $template->param( category => $category, print => scalar $query->param('print') || 0, csv_profiles => [ Koha::CsvProfiles->search({ type => 'marc' }) ], + xsl_exports => CustomXSLTExportList() ); output_html_with_http_headers $query, $cookie, $template->output; --