Subject: | XML::XPathEngine can't return value of 'count' |
It seems that XML::XPathEngine does not return 'count' value as following.
XML:
<kid id="a1" />
<kid id="a2" />
<kid id="a3" />
XPath:
findnodes('count(//kid[@id="a1" or @id="a2"])') # eq 2
I wrote a patch for fixing this problem.
Please check and include.
Regards, Thanks.
Subject: | fix-to-return-count-value.diff |
Index: t/01_basic.t
===================================================================
--- t/01_basic.t (revision 9313)
+++ t/01_basic.t (working copy)
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
use XML::XPathEngine;
BEGIN { push @INC, './t'; }
@@ -44,6 +44,7 @@
is( $xp->findvalue( '//kid1[@att1="v3"]/preceding::gkid2[1]', $tree), 'gkid2 2', "preceding axis[1]");
is( $xp->findvalue( '//kid1[@att1="v3"]/preceding::gkid2[2]', $tree), 'gkid2 1', "preceding axis[1]");
is( $xp->findvalue( '//kid1[@att1="v3"]/preceding::gkid2', $tree), 'gkid2 1gkid2 2', "preceding axis");
+is( $xp->findvalue( 'count(//kid1)', $tree), '3', 'preceding count');
sub init_tree
{ my $tree = tree->new( 'att', name => 'tree', value => 'tree');
Index: lib/XML/XPathEngine.pm
===================================================================
--- lib/XML/XPathEngine.pm (revision 9313)
+++ lib/XML/XPathEngine.pm (working copy)
@@ -106,7 +106,7 @@
if ($results->isa('XML::XPathEngine::NodeSet'))
{ return wantarray ? $results->get_nodelist : $results; }
else
- { return wantarray ? () : XML::XPathEngine::NodeSet->new(); }
+ { return wantarray ? ($results) : $results; } # result should be SCALAR
}