[text/plain 1k]
[MIROD - Wed May 19 10:46:46 2004]:
OK, I got it,
You were swapping things arouond so much in op_gt that you ended up not
reversing the test properly and doing !b<a instead of a<b.
Patch on Expr.pm attached, test below:
#!/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[@att<"4"]' => 'daughter[3]',
'/root/daughter[@att<4]' => 'daughter[3]',
'//daughter[@att<4]' => 'daughter[3]',
'/root/daughter[@att>4]' => 'daughter[5]',
'/root/daughter[@att>5]' => '',
'/root/daughter[@att<3]' => '',
);
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')
. "]" } @_ }
__
Mirod
[text/x-diff 1.6k]
--- Expr.pm 2003-01-26 20:33:24.000000000 +0100
+++ Expr.pm.new 2004-05-19 19:39:22.261681184 +0200
@@ -430,29 +430,21 @@
# (that says: one is a nodeset, and one is not a nodeset)
my ($nodeset, $other);
- my ($true, $false);
+ my ($true, $false)= ( XML::XPath::Boolean->True, XML::XPath::Boolean->False);
if ($lh_results->isa('XML::XPath::NodeSet')) {
- $nodeset = $lh_results;
- $other = $rh_results;
- # we do this because unlike ==, these ops are direction dependant
- ($false, $true) = (XML::XPath::Boolean->False, XML::XPath::Boolean->True);
+ foreach my $node ($lh_results->get_nodelist) {
+ if ($node->to_number->value > $rh_results->to_number->value) {
+ return $true;
+ }
+ }
}
else {
- $nodeset = $rh_results;
- $other = $lh_results;
- # ditto above comment
- ($true, $false) = (XML::XPath::Boolean->False, XML::XPath::Boolean->True);
- }
-
- # True if and only if there is a node in the
- # nodeset such that the result of performing
- # the comparison on <type>(string_value($node))
- # is true.
- foreach my $node ($nodeset->get_nodelist) {
- if ($node->to_number->value > $other->to_number->value) {
- return $true;
+ foreach my $node ($rh_results->get_nodelist) {
+ if ( $lh_results->to_number->value > $node->to_number->value) {
+ return $true;
+ }
}
- }
+ }
return $false;
}
else { # Neither is a nodeset