logo       

Re: LibXSLT / XPathContext interaction: msg#00000

lang.perl.xml

Subject: Re: LibXSLT / XPathContext interaction

Elizabeth Mattijsen <liz@xxxxxxxxxx> writes:

Hallo Liz,

> Looking at XML::LibXML::XPathContext, I wonder whether the following
> should work:
>

Unfortunatelly no.

You seem to be confusing two modules. You're trying to register a
function with XML::LibXML::XPathContext and call it from a XSTL
stylesheet. That won't work. LibXSLT has its own function registering
API. See LibXSLT documentation for that.

Functions registered with XPathContext only can be used with that
context, i.e. if you for example call
$context->find('foo:bar()',$dom). (Note, that there is no relation
between the LibXSLT objects and XPathContext objects).

Petr

> ======================================================
> use strict;
> use warnings;
>
> use XML::LibXML;
> use XML::LibXSLT;
> use XML::LibXML::XPathContext;
>
> my $libxml = XML::LibXML->new;
> my $libxslt = XML::LibXSLT->new;
>
> my $xsltdom = $libxml->parse_string( <<EOD );
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns:foo="urn:foo"
> xsl:exclude-result-prefixes="foo"
>>
>
> <xsl:template match="/">
> <foo><xsl:copy-of select="foo:bar()"/></foo>
> </xsl:template>
>
> </xsl:stylesheet>
> EOD
> my $stylesheet = $libxslt->parse_stylesheet( $xsltdom );
>
> my $xmldom = $libxml->parse_string( "<dom/>" );
> my $context = XML::LibXML::XPathContext->new( $xmldom );
> $context->registerFunctionNS( "bar","urn:foo", sub { print "Bar!\n"; "bar" }
> );
>
> my $newdom = $stylesheet->transform( $xmldom );
> print $stylesheet->output_string( $newdom );
> ======================================================
>
> Instead of the expected output:
>
> -----------------------------------------------------
> Bar!
> <?xml version="1.0"?>
> <foo>bar</foo>
> -----------------------------------------------------
>
> I'm getting:
>
> -----------------------------------------------------
> <?xml version="1.0"?>
> <foo/>
> -----------------------------------------------------
>
> which indicates to me that the registered function is _not_ called.
>
> Am I being too simplistic here and shouldn't this work at all, or am I
> missing something basic here?
>
> Any thoughts on this will be appreciated.
>
>
> Liz
> _______________________________________________
> Perl-XML mailing list
> Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

--
_______________________________________________
Perl-XML mailing list
Perl-XML@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise