With XML::LibXSLT, you implement the LibXML callbacks:
# in your parsing routine:
my $parser = XML::LibXML->new();
local $XML::LibXML::match_cb = \&match_uri;
local $XML::LibXML::open_cb = \&open_uri;
local $XML::LibXML::read_cb = \&read_uri;
local $XML::LibXML::close_cb = \&close_uri;
my $doc = $parser->parse_file($file);
$doc->process_xinclude();
my $style_doc = $parser->parse_file($stylesheet);
my $stylesheet = XML::LibXSLT->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($doc);
...
# the sub definitions:
# NB: This is just one example using a string - the
# return from open_uri is an opaque type, so you can
# use a file handle if that's appropriate
sub match_uri {
my $uri = shift;
# warn("match: $uri\n");
return $uri !~ /^\w+:/; # only handle URI's without a scheme
}
sub open_uri {
my $uri = shift;
# warn("open: $uri\n");
my $str = some_function_to_get_the_uri($uri);
return $str;
}
sub close_uri {
}
sub read_uri {
return substr($_[0], 0, $_[1], "");
}
|