title: Using XPATH to retrieve and extract MARCXML data
body: <p>I'm having some real trouble getting to grips with XPATH, as applied to XML (specifically MARCXML) data. I'm really impressed with its efficiency at helping me track down the code I'm searching for, but I'm having trouble getting to the next step of extracting &amp; working with that code once I've found it.</p>
  
  <p>I have a large set of bibliographic records, pulled from a library catalog in MARCXML. I've put together a long query - a <em>really</em> long query, since it includes duplicate search terms to deal with the case-sensitivity of XPATH - searching certain subfields of each entry for keywords. MARCXML is pretty tidy, so with code that looks like this:</p>
  
  <pre><code>&lt;collection&gt;
    &lt;record&gt;
      &lt;leader&gt;01345cad a25003622c 4564&lt;/leader&gt;
       &lt;controlfield tag="001"&gt;9984333660001531&lt;/controlfield&gt;
       &lt;controlfield tag="005"&gt;20130789942407.2&lt;/controlfield&gt;
       &lt;controlfield tag="008"&gt;850333c19861663nybee    db   201 0 eng  &lt;/controlfield&gt;
       &lt;datafield tag="010" ind1=" " ind2=" "&gt;&lt;subfield code="a"&gt;86448866&lt;/subfield&gt;
       &lt;datafield tag="500" ind1=" " ind2=" "&gt;&lt;subfield code="a"&gt;"Published in Great Britain under the title The Grumble and Bolt Encyclopedia [i.e. Encyclopaedia] of 20th-century Archeology"--T.p. verso.&lt;/subfield&gt;&lt;/datafield&gt;
       &lt;datafield tag="504" ind1=" " ind2=" "&gt;&lt;subfield code="a"&gt;Includes bibliographies and index.&lt;/subfield&gt;&lt;/datafield&gt;
  [...]
  </code></pre>
  
  <p>I'm running an XPATH query that looks like this:</p>
  
  <pre><code>/collection/record/datafield[@tag='500' or @tag='504']//text()[contains(.,'great') or contains(.,'Great') or contains(.,'contents')
  </code></pre>
  
  <p>which will search through records like the one above, and return entries like the one above, since they match my request for records containing "Great" in the 504 field.</p>
  
  <p>I'm using XML Oxygen Developer to run my queries, which sorts through the records and gives me a list of what matched. The problem I'm having is the results displayed in Oxygen:
  <a href="http://i.stack.imgur.com/JvW7P.png" rel="nofollow">screenshot of Oxygen's results window</a>. I'd like to use XPATH to select data from my MARCXML file, but to extract it rather than transform it. If I save the data from the results window I have access to Oracle's "XPATH location", "Resource ID", "Location" data instead of the useful control fields contained in my original XML.</p>
  
  <p>Sorry for such a long post - I wanted to ask if anyone had some advice. My first thoughts are to use XQUERY, reformatting my XPATH query so that it returns or prints the data I want (so 'If' certain fields match certain keywords, Return 'controlfield tag=001, ", " controlfield tag=005", and so on). Or alternatively to use another XML viewer that can find a match and export it intact. Any advice much appreciated! And if I'm short on info please let me know and I can supply more.</p>