The difference is important. Consider this XML document:
Let's return to the books file and add another entry:
<book id="4">
<!-- Perl Cookbook -->
<title>Perl Cookbook</title>
<edition>2</edition>
<authors>
<author>
<firstname>Nathan</firstname>
<lastname>Torkington</lastname>
</author>
<author>
<firstname>Tom</firstname>
<lastname>Christiansen</lastname>
</author>
</authors>
<isbn>123-345-678-90</isbn>
</book>
To identify all books by Tom Christiansen, we need simply say:
my @nodes = $doc->findnodes("/books/book/authors/author/
firstname[text( )='Tom']/../
lastname[text( )='Christiansen']/
../../../title/text( )");
foreach my $node (@nodes) {
print $node->data, "\n";
}
We find the author with
firstname equal to "Tom" and
lastname equal to
"Christiansen", then back out to the
"title" element and get its text child nodes.
Another way to write the backing out is "head out until you find the
book element again":
my @nodes = $doc->findnodes("/books/book/authors/author/
firstname[text( )='Tom']/../
lastname[text( )='Christiansen']/
ancestor::book/title/text( )");