abhishes has asked for the wisdom of the Perl Monks concerning the following question:

Hello All, I have an XSL file in which I have some custom URI like <xsl:include href="myuri:basexsl.xsl" /> When I use apache Xerces api I can implement in the URIResolver interface and implement the logic which will do the uril resolution for me. How do I do the same thing in perl? currently my rendering of the stylesheet is failing as the uri resolution is not happening. regards, Abhishek.

Replies are listed 'Best First'.
Re: URI resolution
by Matts (Deacon) on Jun 20, 2002 at 12:17 UTC
    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], ""); }