PApp::XSLT::LibXSLT - wrapper for an XSLT implementation


PApp documentation Contained in the PApp distribution.

Index


Code Index:

NAME

Top

PApp::XSLT::LibXSLT - wrapper for an XSLT implementation

SYNOPSIS

Top

 use PApp::XSLT::LibXSLT;
 # to be written

DESCRIPTION

Top

The PApp::XSLT::LibXSLT module is a wrapper around XML::LibXSLT. Unless you specifically need XML::LibXSLT you should see PApp::XSLT.

new PApp::XSLT::LibXSLT parameter => value...

Creates a new PApp::XSLT::LibXSLT object with the specified behaviour. All parameters are optional. See PApp::XSLT::new.

SEE ALSO

Top

PApp.

AUTHOR

Top

 Marc Lehmann <schmorp@schmorp.de>
 http://home.schmorp.de/


PApp documentation Contained in the PApp distribution.
package PApp::XSLT::LibXSLT;

$VERSION = 0.12;

no bytes;

use XML::LibXML;
use XML::LibXSLT;

use Convert::Scalar ();

use PApp::Exception;

use base PApp::XSLT;

our $parser;
our $xslt;

sub new($;%) {
   my $class = shift;
   my $self = $class->SUPER::new(@_);
   my %args = @_;

   $parser ||= new XML::LibXML;
   $xslt   ||= new XML::LibXSLT;

   $self;
}

sub _apply($$;@) {
   my $self = shift;
   my $ss = $self->{_ss};

   eval {
      if (!$ss and ref $self->{ss} ne XML::LibXSLT::Stylesheet) {
         if (ref $self->{ss}) {
            # parse it each time :(
            $ss = $xslt->parse_stylesheet(
                     $parser->parse_string(
                        $self->{ss}->()
                     )
                  );
         } else {
            # parse it once :)
            $self->{_ss} = 
            $ss = $xslt->parse_stylesheet(
                     $parser->parse_string(
                        $self->{ss}
                     )
                  );
         }
      }
   };
   if ($@) {
      $self->error("arg:/template", $@);
      return ();
   }

   my $result = eval {
      $ss->output_string($ss->transform(@_));
   };
   if ($@) {
      $self->error("arg:/data", $@);
      return ();
   } else {
      return $result;
   }
}

1;