title: Using XQuery/XPath to get the attribute value of an element's parent node
body: <p>Given this xml document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;mydoc&gt;
          &lt;foo f="fooattr"&gt;
              &lt;bar r="barattr1"&gt;
                  &lt;baz z="bazattr1"&gt;this is the first baz&lt;/baz&gt;
              &lt;/bar&gt;
              &lt;bar r="barattr2"&gt;
                  &lt;baz z="bazattr2"&gt;this is the second baz&lt;/baz&gt;
              &lt;/bar&gt;
          &lt;/foo&gt;
      &lt;/mydoc&gt;
  </code></pre>
  
  <p>that is being processed by this xquery:</p>
  
  <pre><code>let $d := doc('file:///Users/mark/foo.xml')
  let $barnode := $d/mydoc/foo/bar/baz[contains(@z, '2')]
  let $foonode := $barnode/../../@f
  return $foonode
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>"Cannot create an attribute node (f) whose parent is a document node". 
  </code></pre>
  
  <p>It seems that the ../ operation is sort of removing the matching nodes from the rest of the document such that it thinks it's the document node.</p>
  
  <p>I'm open to other approaches but the selection of the parent depends on the child attribute containing a certain sub-string. </p>
  
  <p>Cheers!</p>