Apache-AxKit-Language-LibXSLTEnhanced

 view release on metacpan or  search on metacpan

lib/Apache/AxKit/Util/LibXSLTAddonFunction.pm  view on Meta::CPAN

package Apache::AxKit::Util::LibXSLTAddonFunction;

use strict;

sub new {
    my $class = shift;
    
    my $this = [ [ ] ];
    
    bless $this, $class;
    
    $this->init();
    
    return $this;
}

sub init {
    die "has to be implemened by derived class\n";
}

sub addRegisteredFunction {
    push @{ $_[0]->[0] }, [ $_[1], $_[2] ];
}

sub getNamespace {
    die "has to be implemented by derived class\n";
}

sub getFunctions {
    return @{ $_[0][0] };
}

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

=head1 NAME

Apache::AxKit::Util::LibXSLTAddonFunction - AxKit extension to load perl callbacks for XSL

=head1 SYNOPSIS

  package Apache::AxKit::Util::MiscAddonFunctions;

  use base qw( Apache::AxKit::Util::LibXSLTAddonFunction );
  use strict;
  use XML::LibXML;
         
  my $parser = XML::LibXML->new();

  sub init {
      my $this = shift;
    
      $this->addRegisteredFunction( "staticFunction", \&staticFunction );
      $this->addRegisteredFunction( "instanceMethod", sub { $this->instanceMethod( @_ ) } );
  }

  sub getNamespace {
      return "urn:perl-example-addon";
  }

  sub staticMethod {
      my $val  = shift;

      ## this is not 100% correct
      $val =~ s/<\s+/&lt;/;
    
      my $doc = $parser->parse_string(<<"EOT");
  <tree>
  $val
  </tree>
  EOT
      return $doc->getElementsByTagName("tree");
  }

  sub instanceMethod {
      my $this = shift;
      my $val  = shift;

     ## this is not 100% correct
      $val =~ s/<\s+/&lt;/;

      my $doc = $parser->parse_string(<<"EOT");
  <tree>
  $val
  </tree>
  EOT
      return $doc->getElementsByTagName("tree");
  }

  1;

  ## in XSL
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:UML="org.omg.xmi.namespace.UML"
                              xmlns:str="http://exslt.org/strings"
                              xmlns:pma="urn:perl-example-addon"
                              xmlns:exslt="http://exslt.org/common"
                              extension-element-prefixes="str">



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