Apache-AxKit-Language-LibXSLTEnhanced

 view release on metacpan or  search on metacpan

lib/Apache/AxKit/Language/LibXSLTEnhanced.pm  view on Meta::CPAN

        }
        if (!$changed) {
            AxKit::Debug(7, "[LibXSLT] stylesheet cached");
            $stylesheet = $style_cache{$style->key()}{style};
        }
    }
    
    if (!$stylesheet || ref($stylesheet) ne 'XML::LibXSLT::Stylesheet') {
        reset_depends();
        my $style_uri = $style->apache_request->uri();
        AxKit::Debug(7, "[LibXSLT] parsing stylesheet $style_uri");
        my $style_doc = $style->get_dom();
        
        local($XML::LibXML::match_cb, $XML::LibXML::open_cb,
            $XML::LibXML::read_cb, $XML::LibXML::close_cb);
        Apache::AxKit::LibXMLSupport->reset();
        local $Apache::AxKit::LibXMLSupport::provider_cb = 
            sub {
                my $r = shift;
                my $provider = Apache::AxKit::Provider->new_style_provider($r);
                add_depends($provider->key());
                return $provider;
            };
    
        $stylesheet = XML::LibXSLT->parse_stylesheet($style_doc);
        
        foreach( $r->dir_config->get("LibXSLTFunctionsModule") ) {
            eval("require $_" );
        
            if( $@ ) {
                die "Could not load module.\n $@";
            }
        
            my $function_lib = $_->new();
        
            foreach( $function_lib->getFunctions() ) {
                XML::LibXSLT->register_function( $function_lib->getNamespace(), $_->[0], $_->[1] );
            }
        }

        unless ($r->dir_config('AxDisableXSLTStylesheetCache')) {
            $style_cache{$style->key()} = 
                { style => $stylesheet, mtime => time, depends => [ get_depends() ] };
        }
    }

    # get request form/querystring parameters
    my @params = fixup_params($class->get_params($r));

    AxKit::Debug(7, "[LibXSLT] performing transformation");

    my $results = $stylesheet->transform($xml_doc, @params);
    
    AxKit::Debug(7, "[LibXSLT] transformation finished, creating $results");
    
    if ($last_in_chain) {
        AxKit::Debug(8, "[LibXSLT] outputting to \$r");
        if ($XML::LibXSLT::VERSION >= 1.03) {
            my $encoding = $stylesheet->output_encoding;
            my $type = $stylesheet->media_type;
            $r->content_type("$type; charset=$encoding");
        }
        $stylesheet->output_fh($results, $r);
    }

    AxKit::Debug(7, "[LibXSLT] storing results in pnotes(dom_tree) ($r)");
    $r->pnotes('dom_tree', $results);
    
#         warn "LibXSLT returned $output \n";
#         print $stylesheet->output_string($results);
    return Apache::Constants::OK;

}

sub fixup_params {
    my @results;
    while (@_) {
        push @results, XML::LibXSLT::xpath_to_string(
                splice(@_, 0, 2)
                );
    }
    return @results;
}

1;








# Preloaded methods go here.

1;
__END__
# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

Apache::AxKit::Language::LibXSLTEnhanced - AxKit extension to load perl callbacks for XSL

=head1 SYNOPSIS
  
  <Files *.zuml>
      AxAddStyleMap text/xsl Apache::AxKit::Language::LibXSLTEnhanced
      PerlAddVar LibXSLTFunctionsModule BestSolution::AddonFunctions
  </Files>

=head1 DESCRIPTION

This module is working completly like Language::LibXSLT but it support registering 
perl-functions which can be used in XSL-Stylesheets. To add a Perl-Callbacks you
have to use PerlAddVar as shown in synopsis. The module loaded has to inherit from
L<Apache::AxKit::Util::LibXSLTAddonFunction>

=head2 EXPORT

None by default.



( run in 1.884 second using v1.01-cache-2.11-cpan-39bf76dae61 )