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


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

$parser -> expand_entities (0);
$parser -> load_ext_dtd (0);
 
my $result;
       
my $stylesheet = shift;
my $source     = shift;


my $source_text;
# open FILE, "<$source";
# $source_text = join '', <FILE>;
# close FILE;


use ACIS::Data::DumpXML qw( dump_xml );
use ACIS::Data::DumpXML::Parser;

use Carp::Assert;

#die $source_text;

#my $struct =  ACIS::Data::DumpXML::Parser -> new -> parse ( $source_text );
my $struct =  ACIS::Data::DumpXML::Parser -> new -> parsefile ( $source );

assert( ref $struct );
assert( $struct -> {request} );
assert( $struct -> {response} );
# assert( $struct -> {system} );

$struct->{system}->{config} = { 
			       'site-name' => "AcisTest"
			       };

$struct ->{response} ->{form} = $struct->{form};
delete $struct->{form};


my $xml = dump_xml( $struct );

use utf8;


# die $xml;

$source_text = $xml;

# $source_text = "<data/>";

eval 
  {
#    my $source = $parser -> parse_file ("$source");
    my $source = $parser -> parse_string ( $source_text );
    my $style_doc = $parser -> parse_file ( $stylesheet );
    my $stylesheet = $xslt -> parse_stylesheet( $style_doc );
    my $results = $stylesheet -> transform($source);

    $result = $stylesheet -> output_string($results);
  };

if( $@ ) {
  die $@;
} else {
  print $result;
}

