Subject: | Duplicates are not removed from the result list |
Duplicates are not removed from the result list
The following test case demonstrates it. The attached patch fixes it.
#!/usr/bin/perl -w
use strict;
use XML::XPath;
use Test::More;
my $xml='<root att="root_att"><daughter att="3"/><daughter att="4"/><daughter att="5"/></root>';
my %results= ( '/root/daughter/..' => 'root[root_att]',);
plan tests => scalar keys %results;
my $xpath = XML::XPath->new( xml => $xml);
foreach my $path ( keys %results)
{
my @xpath_result = $xpath->findnodes( $path);
is( dump_nodes( @xpath_result) => $results{$path}, "path: $path");
}
sub dump_nodes
{ return join '-', map { $_->getName . "[" . $_->getAttribute( 'att') . "]" } @_ }
--- NodeSet.pm 2002-09-02 12:25:47.000000000 +0200
+++ NodeSet.pm.new 2004-05-19 18:20:24.704899288 +0200
@@ -18,9 +18,23 @@
sub sort {
my $self = CORE::shift;
@$self = CORE::sort { $a->get_global_pos <=> $b->get_global_pos } @$self;
+ $self->remove_duplicates;
return $self;
}
+sub remove_duplicates {
+ my $self = CORE::shift;
+ my @unique;
+ my $last_node=0;
+ foreach my $node (@$self) {
+ push @unique, $node unless( $node == $last_node);
+ $last_node= $node;
+ }
+ @$self= @unique;
+ return $self;
+}
+
+
sub pop {
my $self = CORE::shift;
CORE::pop @$self;