package XML::Tools;

use 5.004;
use strict;
use warnings;

require Exporter;

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

our @ISA = qw(Exporter);

our %EXPORT_TAGS = ( 'all' => [ qw() ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();

our $VERSION = '0.01';


# Preloaded methods go here.
sub new {
  my $class = shift;
  my %args = @_;

  # Mandatory
  unless(exists $args{'xml'} && exists $args{'xsl'}) {
    carp "Usage : new " . __PACKAGE__ . " (\n" .
      "\t'xml' => \$xml,\n" .
      "\t'xsl' => \$xsl,\n" .
      "\t'verbose'  => 1 ou 0,\n" .
	");\n";
    return undef;
  }

  # Default
  $args{'verbose'} = 0 unless exists $args{'verbose'};

  $args{'params'} = {};

  bless \%args, $class;
}

sub addParams {
  my $self = shift;
  my (%params) = @_;

  while(my($k, $v) = each %params) {
    $self->{'params'}{$k} = $v;
  }
}

sub getParam {
  my $self = shift;
  my $key = shift;

  return exists $self->{'params'}{$key} ? $self->{'params'}{$key} : undef;
}

sub xsltproc {
  my $self = shift;

  my ($parser,$xslt,$source,$style_doc,$stylesheet,$result);

  $parser = XML::LibXML->new();
  $xslt	= XML::LibXSLT->new();
  $xslt->max_depth(2000);
  $source = $parser->parse_file($self->{'xml'});
  $style_doc = $parser->parse_file($self->{'xsl'});
  $stylesheet = $xslt->parse_stylesheet($style_doc);
  $result = $stylesheet->transform($source, %{$self->{'params'}});
  return $stylesheet->output_string($result);
}

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

=head1 NAME

AFP_com::XML::Tools - Perl extension for blah blah blah

=head1 SYNOPSIS

  use AFP_com::XML::Tools;
  blah blah blah

=head1 DESCRIPTION

Stub documentation for AFP_com::XML::Tools, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.

Blah blah blah.

=head2 EXPORT

None by default.



=head1 SEE ALSO

Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.

If you have a mailing list set up for your module, mention it here.

If you have a web site set up for your module, mention it here.

=head1 AUTHOR

Nicolas, E<lt>nicolas@E<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2005 by Nicolas

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.7 or,
at your option, any later version of Perl 5 you may have available.


=cut
