title: Join elements in SimpleXML (PHP)
body: <p>Any idea how can join and ID with another set of data and then print out certain information?
  I want to print out The name and the country of a user. I am stuck already for a few hours and I would appreciate any help and suggestion!</p>
  <p><strong>These are the the files :</strong> <a href="https://drive.google.com/drive/folders/15vi1sW5TExqZBCAz-gUTWF5xYCq9pC4u?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/drive/folders/15vi1sW5TExqZBCAz-gUTWF5xYCq9pC4u?usp=sharing</a></p>
  <p><strong>EDIT: The code that I wrote is the problem. I get partial results but I am missing the &quot;JOIN&quot; between different XML sets of data.</strong></p>
  <p><strong>Edit2: I need to obtain as a result: 1) A project title 2) Acronym 3) Abstract and 4) Partner name and country. I am missing part 4) where I was trying to join based on PartnerRef values and by the list of partners at the end of the xml file.</strong></p>
  <p>**I try to achieve this: **
  <a href="https://i.stack.imgur.com/A3yWG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A3yWG.png" alt="enter image description here" /></a></p>
  <p>XML:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  
  &lt;InfoSystem&gt;
      &lt;Workflows&gt;
          &lt;Workflow&gt;
              &lt;Name&gt;project-workflow&lt;/Name&gt;
              &lt;Transition&gt;
                  &lt;From&gt;in-preparation&lt;/From&gt;
                  &lt;To&gt;submitted&lt;/To&gt;
              &lt;/Transition&gt;
              &lt;Transition&gt;
                  &lt;From&gt;submitted&lt;/From&gt;
                  &lt;To&gt;accepted&lt;/To&gt;
                  &lt;To&gt;rejected&lt;/To&gt;
              &lt;/Transition&gt;
              &lt;Transition&gt;
                  &lt;From&gt;accepted&lt;/From&gt;
                  &lt;To&gt;running&lt;/To&gt;
              &lt;/Transition&gt;
              &lt;Transition&gt;
                  &lt;From&gt;running&lt;/From&gt;
                  &lt;To&gt;completed&lt;/To&gt;
              &lt;/Transition&gt;
          &lt;/Workflow&gt;
      &lt;/Workflows&gt;
      &lt;Projects&gt;
          
          
          &lt;Project&gt;
              &lt;Id&gt;3&lt;/Id&gt;
              &lt;StatusHistory&gt;
                  &lt;Status&gt;
                      &lt;Value&gt;in-preparation&lt;/Value&gt;
                      &lt;Date&gt;2019-01-20&lt;/Date&gt;
                  &lt;/Status&gt;
                  &lt;Status&gt;
                      &lt;Value&gt;submitted&lt;/Value&gt;
                      &lt;Date&gt;2019-03-20&lt;/Date&gt;
                  &lt;/Status&gt;
                  &lt;Status&gt;
                      &lt;Value&gt;rejected&lt;/Value&gt;
                      &lt;Date&gt;2019-06-01&lt;/Date&gt;
                  &lt;/Status&gt;
              &lt;/StatusHistory&gt;
              &lt;Submission&gt;
                  &lt;Title&gt;Secure environments for e-commerce&lt;/Title&gt;
                  &lt;Acronym&gt;SEEC&lt;/Acronym&gt;
                  &lt;Abstract&gt;
                      &lt;Parag&gt;&lt;Fragment&gt;The project aims at providing innovative solutions for secure e-commerce&lt;/Fragment&gt;&lt;/Parag&gt;
                  &lt;/Abstract&gt;
                  
                  &lt;WorkPackages&gt;
                      &lt;WorkPackage&gt;
                          &lt;No&gt;1&lt;/No&gt;
                          &lt;Title&gt;Coordination&lt;/Title&gt;
                          &lt;Tasks&gt;
                              &lt;Task&gt;
                                  &lt;No&gt;1&lt;/No&gt;
                                  &lt;Name&gt;Setting-up the project framework&lt;/Name&gt;
                                  &lt;Start&gt;2019-07-01&lt;/Start&gt;
                                  &lt;End&gt;2019-09-01&lt;/End&gt;
                                  &lt;Effort&gt;
                                      &lt;Partner&gt;
                                          &lt;PartnerRef&gt;4&lt;/PartnerRef&gt;
                                          &lt;DaysNb&gt;20&lt;/DaysNb&gt;
                                      &lt;/Partner&gt;
                                  &lt;/Effort&gt;
                              &lt;/Task&gt;
                              &lt;Task&gt;
                                  &lt;No&gt;2&lt;/No&gt;
                                  &lt;Name&gt;Project management&lt;/Name&gt;
                                  &lt;Start&gt;2019-07-01&lt;/Start&gt;
                                  &lt;End&gt;2019-07-01&lt;/End&gt;
                                  &lt;Effort&gt;
                                      &lt;Partner&gt;
                                          &lt;PartnerRef&gt;4&lt;/PartnerRef&gt;
                                          &lt;DaysNb&gt;100&lt;/DaysNb&gt;
                                      &lt;/Partner&gt;
                                      &lt;Partner&gt;
                                          &lt;PartnerRef&gt;6&lt;/PartnerRef&gt;
                                          &lt;DaysNb&gt;40&lt;/DaysNb&gt;
                                      &lt;/Partner&gt;
                                      &lt;Partner&gt;
                                          &lt;PartnerRef&gt;7&lt;/PartnerRef&gt;
                                          &lt;DaysNb&gt;40&lt;/DaysNb&gt;
                                      &lt;/Partner&gt;
                                  &lt;/Effort&gt;
                              &lt;/Task&gt;
                          &lt;/Tasks&gt;
                          &lt;Deliverables&gt;
                              &lt;Deliverable&gt;
                                  &lt;Id&gt;1&lt;/Id&gt;
                                  &lt;Name&gt;Management report 1&lt;/Name&gt;
                                  &lt;Type&gt;report&lt;/Type&gt;
                                  &lt;DueDate&gt;2019-12-20&lt;/DueDate&gt;
                              &lt;/Deliverable&gt;
                              &lt;Deliverable&gt;
                                  &lt;Id&gt;2&lt;/Id&gt;
                                  &lt;Name&gt;Management report 2&lt;/Name&gt;
                                  &lt;Type&gt;report&lt;/Type&gt;
                                  &lt;DueDate&gt;2020-06-30&lt;/DueDate&gt;
                              &lt;/Deliverable&gt;
                              &lt;Deliverable&gt;
                                  &lt;Id&gt;3&lt;/Id&gt;
                                  &lt;Name&gt;Final management report&lt;/Name&gt;
                                  &lt;Type&gt;report&lt;/Type&gt;
                                  &lt;DueDate&gt;2021-07-01&lt;/DueDate&gt;
                              &lt;/Deliverable&gt;
                          &lt;/Deliverables&gt;
                      &lt;/WorkPackage&gt;
                      &lt;WorkPackage&gt;
                          &lt;No&gt;2&lt;/No&gt;
                          &lt;Title&gt;Design of the platform&lt;/Title&gt;
                          &lt;Tasks&gt;
                              &lt;Task&gt;
                                  &lt;No&gt;1&lt;/No&gt;
                                  &lt;Name&gt;User interface design&lt;/Name&gt;
                                  &lt;Start&gt;2020-09-01&lt;/Start&gt;
                                  &lt;End&gt;2020-12-12&lt;/End&gt;
                                  &lt;Effort&gt;
                                      &lt;Partner&gt;
                                          &lt;PartnerRef&gt;6&lt;/PartnerRef&gt;
                                          &lt;DaysNb&gt;150&lt;/DaysNb&gt;
                                      &lt;/Partner&gt;
                                      &lt;Partner&gt;
                                          &lt;PartnerRef&gt;7&lt;/PartnerRef&gt;
                                          &lt;DaysNb&gt;220&lt;/DaysNb&gt;
                                      &lt;/Partner&gt;
                                  &lt;/Effort&gt;
                              &lt;/Task&gt;
                          &lt;/Tasks&gt;
                          &lt;Deliverables&gt;
                              &lt;Deliverable&gt;
                                  &lt;Id&gt;1&lt;/Id&gt;
                                  &lt;Name&gt;Paper about existing approaches&lt;/Name&gt;
                                  &lt;Type&gt;publication&lt;/Type&gt;
                                  &lt;DueDate&gt;2020-10-30&lt;/DueDate&gt;
                              &lt;/Deliverable&gt;
                          &lt;/Deliverables&gt;
                      &lt;/WorkPackage&gt;
                  &lt;/WorkPackages&gt;
              &lt;/Submission&gt;
          &lt;/Project&gt;
          &lt;Project&gt;
              &lt;Id&gt;4&lt;/Id&gt;
              &lt;StatusHistory&gt;
                  &lt;Status&gt;
                      &lt;Value&gt;in-preparation&lt;/Value&gt;
                      &lt;Date&gt;2022-02-02&lt;/Date&gt;
                  &lt;/Status&gt;
              &lt;/StatusHistory&gt;
              &lt;Submission&gt;
                  &lt;Title&gt;An approach to develop Web-based applications&lt;/Title&gt;
                  &lt;Acronym&gt;WBA&lt;/Acronym&gt;
                  &lt;Abstract&gt;&lt;Parag&gt;&lt;Fragment&gt;The approach relies on the use of semi-structured data&lt;/Fragment&gt;&lt;/Parag&gt;&lt;/Abstract&gt;
              &lt;/Submission&gt;
          &lt;/Project&gt;
      &lt;/Projects&gt;
      &lt;Partners&gt;
          &lt;Partner&gt;
              &lt;Id&gt;1&lt;/Id&gt;
              &lt;Name&gt;UNI1&lt;/Name&gt;
              &lt;Country&gt;CH&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;2&lt;/Id&gt;
              &lt;Name&gt;UNI2&lt;/Name&gt;
              &lt;Country&gt;FR&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;3&lt;/Id&gt;
              &lt;Name&gt;Pear&lt;/Name&gt;
              &lt;Country&gt;BE&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;4&lt;/Id&gt;
              &lt;Name&gt;CIMER&lt;/Name&gt;
              &lt;Country&gt;FR&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;5&lt;/Id&gt;
              &lt;Name&gt;LFPE&lt;/Name&gt;
              &lt;Country&gt;CH&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;6&lt;/Id&gt;
              &lt;Name&gt;UNI3&lt;/Name&gt;
              &lt;Country&gt;IT&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;7&lt;/Id&gt;
              &lt;Name&gt;UNI4&lt;/Name&gt;
              &lt;Country&gt;BE&lt;/Country&gt;
          &lt;/Partner&gt;
          &lt;Partner&gt;
              &lt;Id&gt;8&lt;/Id&gt;
              &lt;Name&gt;APER&lt;/Name&gt;
              &lt;Country&gt;GR&lt;/Country&gt;
          &lt;/Partner&gt;
      &lt;/Partners&gt;
      &lt;Publications&gt;
          &lt;PaperInJournal&gt;
              &lt;Id&gt;1&lt;/Id&gt;
              &lt;Title&gt;Principles of remote learning&lt;/Title&gt;
              &lt;Authors&gt;
                  &lt;Author&gt;
                      &lt;FirstName&gt;Alain&lt;/FirstName&gt;
                      &lt;LastName&gt;Térieur&lt;/LastName&gt;
                  &lt;/Author&gt;
                  &lt;Author&gt;
                      &lt;FirstName&gt;Alex&lt;/FirstName&gt;
                      &lt;LastName&gt;Térieur&lt;/LastName&gt;
                  &lt;/Author&gt;
              &lt;/Authors&gt;
              &lt;Year&gt;2022&lt;/Year&gt;
              &lt;Journal&gt;Journal of e-learning&lt;/Journal&gt;
              &lt;Vol&gt;3&lt;/Vol&gt;
              &lt;No&gt;11&lt;/No&gt;
              &lt;Pages&gt;
                  &lt;From&gt;34&lt;/From&gt;
                  &lt;To&gt;45&lt;/To&gt;
              &lt;/Pages&gt;
          &lt;/PaperInJournal&gt;
          &lt;PaperInJournal&gt;
              &lt;Id&gt;2&lt;/Id&gt;
              &lt;Title&gt;Authoring multimedia&lt;/Title&gt;
              &lt;Authors&gt;
                  &lt;Author&gt;
                      &lt;FirstName&gt;Anne&lt;/FirstName&gt;
                      &lt;LastName&gt;Dupont&lt;/LastName&gt;
                  &lt;/Author&gt;
                  &lt;Author&gt;
                      &lt;FirstName&gt;Victor&lt;/FirstName&gt;
                      &lt;LastName&gt;Térieur&lt;/LastName&gt;
                  &lt;/Author&gt;
              &lt;/Authors&gt;
              &lt;Year&gt;2021&lt;/Year&gt;
              &lt;Journal&gt;Information systems&lt;/Journal&gt;
              &lt;Vol&gt;5&lt;/Vol&gt;
              &lt;No&gt;3&lt;/No&gt;
              &lt;Pages&gt;
                  &lt;From&gt;134&lt;/From&gt;
                  &lt;To&gt;145&lt;/To&gt;
              &lt;/Pages&gt;
          &lt;/PaperInJournal&gt;
      &lt;/Publications&gt;
  &lt;/InfoSystem&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>php code:</p>
  <pre class="lang-php prettyprint-override"><code>    &lt;?php
      include 'info-systems.php';
      include 'example.php';
      
      $InfoSystem = simplexml_load_file(&quot;info-systems.xml&quot;);
      
      foreach($InfoSystem-&gt;xpath('//Project') as $project){
          $projectId = $project-&gt;Id;
          $selectedPartner = $project-&gt;xpath('//PartnerRef');
          //print_r($selectedPartner);
          echo &quot;Title: &quot; . $project-&gt;Submission-&gt;Title;
          echo &quot;&lt;br&gt;&quot;;
          echo &quot;Acronym: &quot; . $project-&gt;Submission-&gt;Acronym;
          echo &quot;&lt;br&gt;&quot;;
          echo &quot;Abstract: &quot; . $project-&gt;Submission-&gt;Abstract-&gt;Parag-&gt;Fragment;
          echo &quot;&lt;br&gt;&quot;;
          echo $project-&gt;Submission-&gt;Abstract-&gt;List-&gt;asXML();
          echo &quot;&lt;br&gt;&quot;;
      
          foreach($InfoSystem-&gt;xpath('//Partner') as $partner){
      
                  if(in_array(1, $selectedPartner, TRUE)){ // This doesn't work at all
                      echo 'Name: ' . $partner-&gt;Name;
                      echo 'Country: ' . $partner-&gt;Country;
                  }
      
              //echo $partner-&gt;Name;
             
          }
      
          echo &quot;&lt;br&gt;&lt;br&gt;&quot;;
      }
  
  ?&gt;
  </code></pre>