title: Nodelist with values and parent's attribute as names
body: <p>I'm new to XML files and am trying to get out some values using XPath. I will plot this values in Jenkins using the <a href="https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin" rel="nofollow noreferrer">Plot plugin</a>. This takes the element names on the x-axis and the element value on the y-axis.</p>
  
  <p>My xml file looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;foo&gt;
      &lt;file file_name="file1.c"&gt;
          &lt;metrics&gt;
              &lt;metric id="M1"&gt;15&lt;/metric&gt;
              &lt;metric id="M2"&gt;7&lt;/metric&gt;
              &lt;metric id="M3"&gt;9&lt;/metric&gt;
          &lt;/metrics&gt;
      &lt;/file&gt;
      &lt;file file_name="file2.c"&gt;
          &lt;metrics&gt;
              &lt;metric id="M1"&gt;1110&lt;/metric&gt;
              &lt;metric id="M2"&gt;56&lt;/metric&gt;
              &lt;metric id="M3"&gt;1&lt;/metric&gt;
          &lt;/metrics&gt;
      &lt;/file&gt;
  &lt;/foo&gt;
  </code></pre>
  
  <p>I want to plot <code>M1</code> for all <code>file_name</code>, therefore what I need to get back using XPath is a <code>nodelist</code> like</p>
  
  <pre><code>&lt;file1.c&gt;15&lt;/file1.c&gt;
  &lt;file2.c&gt;1110&lt;/file1.c&gt;
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>//file/metrics/*[@id='M1']
  </code></pre>
  
  <p>but so I get</p>
  
  <pre><code>&lt;metric id="M1"&gt;15&lt;/metric&gt;
  &lt;metric id="M1"&gt;15&lt;/metric&gt;
  </code></pre>
  
  <p>I found some similar questions, but couldn't adapt it to my case:
  <a href="https://stackoverflow.com/questions/28237694/xpath-get-parent-node-from-child">This</a> for example gets back the parent element including all children.</p>
  
  <p>How can I achieve what I need?</p>