first
second
third
fourth
fifth
sixth
first
second
third
fourth
fifth
sixth
##
use strict;
use XML::Twig;
my $twig = new XML::Twig(
);
$twig->parsefile('1.xml');
my $count = $twig->get_xpath('//fig//label');
for my $c (0..($count-1))
{
my $t = $twig->get_xpath('//fig//label', $c); #//fig/label -here problem comes
my $pl = $twig->get_xpath('//fig//caption', $c);
#my $cc = $t->print;# print for testing
#my $aa = $twig->print; #print for testing
#print "$cc\n\n$c\n**$aa\n";
my $cut = $t->cut ;
$cut->paste('first_child', $pl) ;
}
$twig->print;
####
Correct Output: XPath Expression - "//fig//label"
---------------
first
second
third
fourth
fifth
sixth
####
Wrong output: XPath Expression - "//fig/label"
-------------
first
second
third
fourth
fifth
sixth