use Test;
BEGIN { plan tests => 5 }
use XML::LibXSLT;
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
ok($parser); ok($xslt);
local $XML::LibXML::match_cb = \&match_cb;
local $XML::LibXML::open_cb = \&open_cb;
local $XML::LibXML::close_cb = \&close_cb;
local $XML::LibXML::read_cb = \&read_cb;
my $source = $parser->parse_string(<<'EOT','/foo');
EOT
my $foodoc = <<'EOT';
typed data in stylesheet
Data:
EOT
my $style = $parser->parse_string($foodoc,'foo');
ok($style);
my $stylesheet = $xslt->parse_stylesheet($style);
# my $stylesheet = $xslt->parse_stylesheet_file("example/document.xsl");
my $results = $stylesheet->transform($source);
ok($results);
ok($results->toString, qr/typed data in stylesheet/);
###############################################################
# Callbacks - this is needed because with document('') now,
# libxslt expects to re-get the entire file and re-parse it,
# rather than its old behaviour, which was to use the internal
# DOM. So we have to use callbacks to be able to return the
# original file. We also need to make sure that the call
# to $parser->parse_string($foodoc, 'foo') gets a URI (second
# param), otherwise it doesn't know what to fetch.
sub match_cb {
my $uri = shift;
if ($uri eq 'foo') {
return 1;
}
return 0;
}
sub open_cb {
my $uri = shift;
return $foodoc;
}
sub close_cb {
}
sub read_cb {
return substr($_[0], 0, $_[1], "");
}