| Catalyst-View-XSLT documentation | Contained in the Catalyst-View-XSLT distribution. |
Catalyst::View::XSLT::XML::LibXSLT - An implementation for Catalyst::View::XSLT with XML::LibXSLT
This module is meant to be used internally by Catalyst::View::XSLT.
Returns a new instance of XML::LibXSLT view implementation
Martin Grigorov, <mcgregory {at} e-card {dot} bg>
Simon Bertrang, <simon.bertrang@puzzworks.com>
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| Catalyst-View-XSLT documentation | Contained in the Catalyst-View-XSLT distribution. |
package Catalyst::View::XSLT::XML::LibXSLT; use strict; use warnings; our $VERSION = '0.08';
sub new { my ($proto, $c, $params) = @_; eval { require XML::LibXML; require XML::LibXSLT; XML::LibXML->import; XML::LibXSLT->import; }; if ($@) { $c->error('Could not use XML::LibXSLT: ' . $@); return undef; } if (exists $params->{register_function} and ref($params->{register_function}) eq 'ARRAY') { my $register_subs = $params->{register_function}; foreach my $hrefSubConf (@{ $register_subs }) { XML::LibXSLT->register_function( $hrefSubConf->{uri}, $hrefSubConf->{name}, $hrefSubConf->{subref}, ); } } my $class = ref $proto || $proto; my $self = {}; bless($self, $class); return $self; }
sub process { my ($self, $template, $args, $base) = @_; my ($result, $error) = ('', undef); eval { my $xmlParser = XML::LibXML->new(); my $xsltProcessor = XML::LibXSLT->new(); my ($xmlDocument, $xsltStylesheet); my $xml = delete $args->{xml}; if ($xml =~ m/\</) { $xmlDocument = $xmlParser->parse_string($xml); } elsif (ref($xml) && $xml->isa('GLOB')) { $xmlDocument = $xmlParser->parse_fh($xml); } elsif (ref($xml) && $xml->isa('XML::LibXML::Document')) { $xmlDocument = $xml; } else { $xmlDocument = $xmlParser->parse_file($xml); } if ($template =~ m/\</) { $xsltStylesheet = $xmlParser->parse_string($template, $base); } elsif (ref($template) && $template->isa('GLOB')) { $xsltStylesheet = $xmlParser->parse_fh($template, $base); } elsif (ref($template) && $template->isa('XML::LibXML::Document')) { $xsltStylesheet = $template; } else { $xsltStylesheet = $xmlParser->parse_file($template); } my $xsltTransformer = $xsltProcessor->parse_stylesheet($xsltStylesheet); my %params = XML::LibXSLT::xpath_to_string( %{$args} ); my $results = $xsltTransformer->transform($xmlDocument, %params); $result = $xsltTransformer->output_string($results); }; $error = $@; return ($result, $error); }
1;