title: How can I extract the desired nodes from this XML file using Perl and XPath?
body: <p>After executing a XPath expression for extracting all year and value elements associated with death rates from a XML DB file, I want to take each node from the node list and find the year node, print that, find the value node, and print that all separately. The problem is that the output does not show anything. </p>
  
  <p>The XML content looks like this:</p>
  
  <pre><code>&lt;dataset type="country" name="Afghanistan" total="222"&gt;
  ...
          &lt;data&gt;
               &lt;country id="AFG"&gt;Afghanistan&lt;/country&gt;
               &lt;indicator id="SP.DYN.CDRT.IN"&gt;Death rate, crude (per 1,000 people)&lt;/indicator&gt;
               &lt;year&gt;2006&lt;/year&gt;
               &lt;value&gt;20.3410000&lt;/value&gt;
             &lt;/data&gt;
             &lt;data&gt;
               &lt;country id="AFG"&gt;Afghanistan&lt;/country&gt;
               &lt;indicator id="SP.DYN.CDRT.IN"&gt;Death rate, crude (per 1,000 people)&lt;/indicator&gt;
               &lt;year&gt;2007&lt;/year&gt;
               &lt;value&gt;19.9480000&lt;/value&gt;
             &lt;/data&gt;
             &lt;data&gt;
               &lt;country id="AFG"&gt;Afghanistan&lt;/country&gt;
               &lt;indicator id="SP.DYN.CDRT.IN"&gt;Death rate, crude (per 1,000 people)&lt;/indicator&gt;
               &lt;year&gt;2008&lt;/year&gt;
               &lt;value&gt;19.5720000&lt;/value&gt;
             &lt;/data&gt;
             &lt;data&gt;
               &lt;country id="AFG"&gt;Afghanistan&lt;/country&gt;
               &lt;indicator id="IC.EXP.DOCS"&gt;Documents to export (number)&lt;/indicator&gt;
               &lt;year&gt;2005&lt;/year&gt;
               &lt;value&gt;7.0000000&lt;/value&gt;
             &lt;/data&gt;
             &lt;data&gt;
               &lt;country id="AFG"&gt;Afghanistan&lt;/country&gt;
               &lt;indicator id="IC.EXP.DOCS"&gt;Documents to export (number)&lt;/indicator&gt;
               &lt;year&gt;2006&lt;/year&gt;
               &lt;value&gt;12.0000000&lt;/value&gt;
             &lt;/data&gt;
             &lt;data&gt;
               &lt;country id="AFG"&gt;Afghanistan&lt;/country&gt;
               &lt;indicator id="IC.EXP.DOCS"&gt;Documents to export (number)&lt;/indicator&gt;
               &lt;year&gt;2007&lt;/year&gt;
               &lt;value&gt;12.0000000&lt;/value&gt;
             &lt;/data&gt;
  ...
  &lt;/dataset&gt;
  </code></pre>
  
  <p>The Perl code looks like this:</p>
  
  <pre><code>#Use XML Xlib parser to find elements related to death rate
  
  my $parser = XML::LibXML-&gt;new();
  my $tree = $parser-&gt;parse_file($XML_DB);
  my $root = XML::LibXML::XPathContext-&gt;new($tree-&gt;documentElement());
  #print $nodeSet-&gt;to_literal(); 
  
  foreach my $node ($root-&gt;findnodes("/*/data/indicator[\@id = 'SP.DYN.CDRT.IN']/following-sibling::*")) {
      #print $node-&gt;textContent() . "\n";
      #print $node-&gt;nodeName . "\n";
      print $node-&gt;find("year") . "\n";
  }
  exit;
  </code></pre>