[xml] Re: Problem with XML::LibXSLT Extension function returning nodelist.

Thanks Tod - that sounds like it should work.

The error messges made me think that maybe the node was getting garbage collected twice,
but if returning a single node works then it must be something else.


Tod Harter wrote:

I just dealt with a fairly similar problem on Linux. The only minor difference being instead of throwing an error LibXSLT just sat and ate 100% CPU forever on return from the callback.

I discovered a few things...

1. It makes no difference what the ownership of the elements is, they can just as well be unowned element nodes etc. 2. Your nodelist returned from the callback MUST have exactly ONE node! I only tried returning element nodes, but in my case as long as I returned just one node things worked fine. That returned node can itself have whatever children you want.

Once you get back to XSLT things should work Fine, ie something like <xsl:copy-of select='myextprefix:myfunc()'/> should result in inserting the one returned node and all its children.

There could be various possible reasons for these problems, maybe just slightly broken bindings to perl (which it seems is a fairly common issue with XML::LibXSLT...) or a namespace issue, or something to do with ownership of the nodes (although playing with that never did seem to help in my case).

Code like

       my $df = XML::LibXML::NodeList->new();
       my $e = XML::LibXML::Element->new('key');
       $e->appendText('some text');
       my $f = XML::LibXML::Element->new('key2');
       $f->appendText('some text2');

use Data::Dumper;
print "df is : ".Dumper($df)."\n";
       return $df;

definitely works for me on Linux though at this point...

Mike Trotman wrote:


I'm not sure if this is a Perl or libxml question.

I have an XSLT stylesheet which process multiple XML files.
I have added extension functions to lookup information (based on attributes in the XML) from a different, constant XML file and return a nodelist of additional information which is used in a for-each loop in the XSLT.

This all works fine in Windows XP.

But under Linux - using variuous versions of libxml/libxslt - I get a segmentation or memory fault error:
Recoding from TM_OUT to CM_OUT
.*** glibc detected *** double free or corruption (fasttop): 0x08c787e8 ***

If I set the extension functions to return an empty NodeList then I get no errors
(but obviously not the output I want!).

I have also tried creating a new XML::LibXML::NodeList,
cloning each node found from the constant XML file,
setting the owner document to the current XML data
and pushing these nodes onto the new nodelist.
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
my $dumndlist=XML::LibXML::NodeList->new();
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
my $fn_drgcombo= sub    {
my $tandem_UID=shift || '""';
my $root=shift;

###return $dumndlist;

my $od=$root->get_node(0)->ownerDocument();
my $newl=XML::LibXML::NodeList->new();
my $nl=$drgcombo->findnodes('/DRGCOMBOLIST/item[ UID='.$tandem_UID.']');
for my $n ($nl->get_nodelist() )        {
       my $nn=$n->cloneNode(1);

return $newl;
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

but I still get the memory error.

Any idea how to return a nodelist from an extension function in XML::LibXSLT
(or is this a bug)?


Mike Trotman

Message Scanned by ClamAV on datalucid.com
Perl-XML mailing list
Perl-XML listserv ActiveState com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

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

Message Scanned by ClamAV on datalucid.com

Message Scanned by ClamAV on datalucid.com

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]