title: XSL: combining the results of two XML files
body: <p>I am using XSL 3.0 to create a single XML file which combines two source XML files (XSL and both XML files in same directory). The sources are called people.xml and depositions.xml.</p>
  
  <p>The people.xml file is a list of people, and it looks like this:</p>
  
  <pre><code>&lt;personlist&gt;
   &lt;person id="foo_andrew"&gt;
    &lt;lastname&gt;Foo&lt;/lastname&gt;
    &lt;firstname&gt;Andrew&lt;/firstname&gt;
   &lt;/person&gt;
   &lt;person id="foo_barbara"&gt;
    &lt;lastname&gt;Foo&lt;/lastname&gt;
    &lt;firstname&gt;Barbara&lt;/firstname&gt;
   &lt;/person&gt;
   &lt;person id="foo_chris"&gt;
    &lt;lastname&gt;Foo&lt;/lastname&gt;
    &lt;firstname&gt;Chris&lt;/firstname&gt;
   &lt;/person&gt;
   ...
  &lt;/personlist&gt;
  </code></pre>
  
  <p>These people from this file appear in the deposition file using the <code>@id</code>:</p>
  
  <pre><code>&lt;corpus&gt;
    &lt;deposition id="1"&gt;
     &lt;p n="1"&gt;Suspendisse eu nunc &lt;person id="foo_andrew"/&gt;tristique ex aliquam imperdiet. Quisque volutpat est sed &lt;person id="foo_barbara"/&gt;ullamcorper ultricies. Proin vel nunc in arcu tristique finibus.&lt;/p&gt;
     &lt;p n="2"&gt;Cras a dolor consequat,  &lt;person id="foo_chris"/&gt;congue leo et, porttitor mi. Integer pretium tellus id lobortis faucibus.&lt;/p&gt;
     &lt;p n="3"&gt;Quisque facilisis dui tincidunt &lt;person id="foo_andrew"/&gt;semper blandit. Aenean auctor sem augue, sit amet malesuada neque mattis id.&lt;/p&gt;
    &lt;/deposition&gt;
    &lt;deposition id="2"&gt;
     &lt;p n="1"&gt;Suspendisse eu nunc tristique ex aliquam imperdiet. Quisque volutpat est sed ullamcorper ultricies. Proin vel nunc in arcu tristique finibus.&lt;/p&gt;
     &lt;p n="2"&gt;Cras a dolor consequat, congue leo et, &lt;person id="foo_barbara"/&gt;porttitor mi. Integer pretium tellus id lobortis faucibus.&lt;/p&gt;
     &lt;p n="3"&gt;Quisque facilisis dui &lt;person id="foo_chris"/&gt;tincidunt semper blandit. Aenean auctor sem augue, sit amet malesuada neque mattis id.&lt;/p&gt;
    &lt;/deposition&gt;
    &lt;deposition id="3"&gt;
     &lt;p n="1"&gt;Suspendisse eu nunc tristique &lt;person id="foo_chris"/&gt;ex aliquam imperdiet. Quisque volutpat est sed ullamcorper ultricies. Proin vel nunc in arcu tristique finibus.&lt;/p&gt;
     &lt;p n="2"&gt;Cras a &lt;person id="foo_andrew"/&gt;dolor consequat, congue leo et, porttitor mi. Integer pretium tellus id lobortis faucibus.&lt;/p&gt;
     &lt;p n="3"&gt;Quisque &lt;person id="foo_barbara"/&gt;facilisis dui tincidunt semper blandit. Aenean auctor sem augue, sit amet malesuada neque mattis id.&lt;/p&gt;
    &lt;/deposition&gt;
  &lt;/corpus&gt;
  </code></pre>
  
  <p>I would like to output an XML file that takes combines every appearance of the person into one file. It would look something like the following, where
  - a <code>&lt;deposition&gt;</code> is created for each time the person appears in a deposition
  - but only one <code>&lt;deposition&gt;</code> is created, even if they appear multiple times</p>
  
  <pre><code>&lt;personappear&gt;
   &lt;person id="foo_andrew"&gt;
    &lt;lastname&gt;Foo&lt;/lastname&gt;
    &lt;firstname&gt;Andrew&lt;/firstname&gt;
    &lt;listappear&gt;
     &lt;deposition&gt;1&lt;/deposition&gt;
     &lt;deposition&gt;3&lt;/deposition&gt;
    &lt;/listappear&gt;
   &lt;/person&gt;
   &lt;person id="foo_barbara"&gt;
    &lt;lastname&gt;Foo&lt;/lastname&gt;
    &lt;firstname&gt;Barbara&lt;/firstname&gt;
    &lt;listappear&gt;
     &lt;deposition&gt;1&lt;/deposition&gt;
     &lt;deposition&gt;2&lt;/deposition&gt;
     &lt;deposition&gt;3&lt;/deposition&gt;
    &lt;/listappear&gt;
   &lt;/person&gt;
   &lt;person id="foo_chris"&gt;
    &lt;lastname&gt;Foo&lt;/lastname&gt;
    &lt;firstname&gt;Chris&lt;/firstname&gt;
    &lt;listappear&gt;
     &lt;deposition&gt;1&lt;/deposition&gt;
     &lt;deposition&gt;2&lt;/deposition&gt;
     &lt;deposition&gt;3&lt;/deposition&gt;
    &lt;/listappear&gt;
   &lt;/person&gt;
   ...
  &lt;/personlist&gt;
  </code></pre>
  
  <p>I can't figure even figure out the basics of how to access two separate XML files in one XSL! This is blocking me from deploying keys, etc to combine the records.</p>
  
  <p>Thanks very much in advance.</p>