title: Extracting Data from XBRL with XPath
body: <p>I'm trying to extract some data points from an XBRL file, using an XPath expression in Talend Studio.  I want to extract all the ShareHolderFunds values and the end date for the period it relates to (referenced by the "ContextRef" attribute), along with the the company registered number.  I'm struggling making the link to the period end date - at the moment my code incorrectly returns the same end date for both ShareHolderFund values.</p>
  
  <p>Here's a screenshot of my code Talend Studio:</p>
  
  <p><img src="https://i.stack.imgur.com/79mBs.png" alt="Talend Studio"></p>
  
  <p>And here's an extract of the XBRL:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/stylesheet/CH-AE-stylesheet.xsl"?&gt;
  &lt;xbrl xmlns="http://www.xbrl.org/2003/instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ae="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21" xmlns:gc="http://www.xbrl.org/uk/fr/gcd/2004-12-01" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:pt="http://www.xbrl.org/uk/fr/gaap/pt/2004-12-01" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
  &lt;link:schemaRef xlink:arcrole="http://www.w3.org/1999/xlink/properties/linkbase" xlink:href="http://www.companieshouse.gov.uk/ef/xbrl/uk/fr/gaap/ae/2009-06-21/uk-gaap-ae-2009-06-21.xsd" xlink:type="simple" /&gt;
  &lt;ae:CompanyNotDormant contextRef="y2013"&gt;true&lt;/ae:CompanyNotDormant&gt;
  &lt;gc:EntityNames&gt;
    &lt;gc:EntityCurrentLegalName contextRef="y2013"&gt;A &amp;amp; Co. Limited&lt;/gc:EntityCurrentLegalName&gt;
  &lt;/gc:EntityNames&gt;
  &lt;ae:CompanyIdentifyingNumbers&gt;
    &lt;ae:CompaniesHouseRegisteredNumber contextRef="y2013"&gt;123456&lt;/ae:CompaniesHouseRegisteredNumber&gt;
  &lt;/ae:CompanyIdentifyingNumbers&gt;
  &lt;gc:StatementDatesPeriodsCovered&gt;
    &lt;gc:BalanceSheetDate contextRef="e2013"&gt;2013-03-31&lt;/gc:BalanceSheetDate&gt;
  &lt;/gc:StatementDatesPeriodsCovered&gt;
  
  &lt;pt:ShareholderFunds precision="5" contextRef="e2013" unitRef="GBP"&gt;5286&lt;/pt:ShareholderFunds&gt;
  &lt;pt:ShareholderFunds precision="5" contextRef="e2012" unitRef="GBP"&gt;5446&lt;/pt:ShareholderFunds&gt;
  
  &lt;unit id="shares"&gt;
    &lt;measure&gt;xbrli:shares&lt;/measure&gt;
  &lt;/unit&gt;
  &lt;unit id="GBP"&gt;
    &lt;measure&gt;iso4217:GBP&lt;/measure&gt;
  &lt;/unit&gt;
  &lt;unit id="pure"&gt;
    &lt;measure&gt;xbrli:pure&lt;/measure&gt;
  &lt;/unit&gt;
  
  &lt;context id="e2012"&gt;
    &lt;entity&gt;
      &lt;identifier scheme="Ellco/results"&gt;A &amp;amp; Co. Limited&lt;/identifier&gt;
    &lt;/entity&gt;
    &lt;period&gt;
      &lt;instant&gt;2012-03-31&lt;/instant&gt;
    &lt;/period&gt;
  &lt;/context&gt;
  &lt;context id="s2013"&gt;
    &lt;entity&gt;
      &lt;identifier scheme="Ellco/results"&gt;A &amp;amp; Co. Limited&lt;/identifier&gt;
    &lt;/entity&gt;
    &lt;period&gt;
      &lt;instant&gt;2012-03-31&lt;/instant&gt;
    &lt;/period&gt;
  &lt;/context&gt;
  &lt;context id="e2013"&gt;
    &lt;entity&gt;
      &lt;identifier scheme="Ellco/results"&gt;A &amp;amp; Co. Limited&lt;/identifier&gt;
    &lt;/entity&gt;
    &lt;period&gt;
      &lt;instant&gt;2013-03-31&lt;/instant&gt;
    &lt;/period&gt;
  &lt;/context&gt;
  &lt;ae:CompaniesHouseDocumentAuthentication contextRef="y2013"&gt; &lt;/ae:CompaniesHouseDocumentAuthentication&gt;
  &lt;ae:DateAccountsReceived contextRef="e2013"&gt;2013-12-25&lt;/ae:DateAccountsReceived&gt;
  &lt;/xbrl&gt;
  </code></pre>