View | Details | Raw Unified | Return to bug 13262
Collapse All | Expand All

(-)a/Koha/XSLT_Handler.pm (-3 / +11 lines)
Lines 128-134 __PACKAGE__->mk_accessors(qw( do_not_return_source print_warns )); Link Here
128
128
129
=head2 transform
129
=head2 transform
130
130
131
    my $output= $xslt_engine->transform( $xml, $xsltfilename );
131
    my $output= $xslt_engine->transform( $xml, $xsltfilename, [$parameters] );
132
    if( $xslt_engine->err ) {
132
    if( $xslt_engine->err ) {
133
        #decide what to do on failure..
133
        #decide what to do on failure..
134
    }
134
    }
Lines 144-150 __PACKAGE__->mk_accessors(qw( do_not_return_source print_warns )); Link Here
144
=cut
144
=cut
145
145
146
sub transform {
146
sub transform {
147
    my ( $self, $orgxml, $file ) = @_;
147
    my ( $self, $orgxml, $file, $parameters ) = @_;
148
148
149
    #Initialized yet?
149
    #Initialized yet?
150
    if ( !$self->{xslt_hash} ) {
150
    if ( !$self->{xslt_hash} ) {
Lines 182-188 sub transform { Link Here
182
        return $retval;
182
        return $retval;
183
    }
183
    }
184
    my $str = eval {
184
    my $str = eval {
185
        my $result = $stsh->transform($source);
185
        #$parameters is an optional hashref that contains
186
        #key-value pairs to be sent to the XSLT.
187
        #Numbers may be bare but strings must be double quoted
188
        #(e.g. "'string'" or '"string"'). See XML::LibXSLT for
189
        #more details.
190
191
        #NOTE: Parameters are not cached. They are provided for
192
        #each different transform.
193
        my $result = $stsh->transform($source, %$parameters);
186
        $stsh->output_as_chars($result);
194
        $stsh->output_as_chars($result);
187
    };
195
    };
188
    if ($@) {
196
    if ($@) {
(-)a/t/db_dependent/XSLT_Handler.t (-1 / +12 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use FindBin;
22
use FindBin;
23
use Test::More tests => 24;
23
use Test::More tests => 26;
24
24
25
use Koha::XSLT_Handler;
25
use Koha::XSLT_Handler;
26
26
Lines 116-119 $output= $engine->transform( $xml_2, $xsltfile_3 ); Link Here
116
is( $engine->err, undef, 'Unexpected error on transform with third xsl' );
116
is( $engine->err, undef, 'Unexpected error on transform with third xsl' );
117
is( $engine->refresh, 2, 'Final test on clearing cache' );
117
is( $engine->refresh, 2, 'Final test on clearing cache' );
118
118
119
my $xsltfile_4 = 'test04.xsl';
120
is( -e $path.$xsltfile_4, 1, "Found my test stylesheet $xsltfile_4" );
121
exit if !-e $path.$xsltfile_4;
122
$xsltfile_4 = $path.$xsltfile_4;
123
my $parameters = { injected_variable => "'this is a test'",};
124
$output = $engine->transform($xml_1, $xsltfile_4, $parameters);
125
require XML::LibXML;
126
my $dom = XML::LibXML->load_xml(string => $output);
127
my $result = $dom->find( '/just_a_tagname' );
128
is ( $result->to_literal(), 'this is a test', "Successfully injected string into XSLT parameter/variable");
129
119
#End of tests
130
#End of tests
(-)a/t/db_dependent/XSLT_Handler/test04.xsl (-1 / +18 lines)
Line 0 Link Here
0
- 
1
<xsl:stylesheet version="1.0"
2
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
    xmlns:marc="http://www.loc.gov/MARC21/slim"
4
>
5
  <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/>
6
  <xsl:param name="injected_variable" />
7
8
  <xsl:template match="/">
9
      <xsl:apply-templates/>
10
  </xsl:template>
11
12
  <xsl:template match="node()">
13
    <xsl:copy>
14
   <xsl:value-of select="$injected_variable"/>
15
    </xsl:copy>
16
  </xsl:template>
17
18
</xsl:stylesheet>

Return to bug 13262