title: Parent node output on if child of sibling node exists XSLT
body: <p>I need to get an output of a parent node that has the same contents of a certain element in another XML file. I am new to XSLT so I am hoping you can help me point out my mistake.</p>
  
  <p>Here is my external xml: "XML2.xml"</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
      &lt;section&gt;
          &lt;sub-section&gt;
              &lt;chapter&gt;Chapter 1&lt;/chapter&gt;
          &lt;/sub-section&gt;
          &lt;sub-sectionB&gt;
              &lt;author&gt;Author 1A&lt;/author&gt;
              &lt;author&gt;Author 2B&lt;/author&gt;
          &lt;/sub-sectionB&gt; 
      &lt;/section&gt;
      &lt;section&gt;
          &lt;sub-section&gt;
              &lt;chapter&gt;Chapter 2&lt;/chapter&gt;
          &lt;/sub-section&gt;
          &lt;sub-sectionB&gt;
              &lt;author&gt;Author 1D&lt;/author&gt;
              &lt;author&gt;Author 2C&lt;/author&gt;
          &lt;/sub-sectionB&gt; 
       &lt;/section&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>My Main XML: XML1.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rules&gt;
      &lt;somerules&gt;
          &lt;rule1&gt;Author 1A&lt;/rule1&gt;
      &lt;/somerules&gt;
      &lt;somerules&gt;
          &lt;rule1&gt;Author 1C&lt;/rule1&gt;
      &lt;/somerules&gt;
  &lt;/rules&gt;
  </code></pre>
  
  <p>My XSLT attempt: XMLRULES.xslt</p>
  
  <pre><code>?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="2.0"&gt;
  
      &lt;xsl:param name="xinput" select="document('XML2.xml')"/&gt;
  
      &lt;xsl:template match="/"&gt;
          &lt;xsl:variable name="var1" select="$xinput/root/section/sub-sectionB/author"/&gt;            
              &lt;xsl:for-each select="/rules/somerules/rule1[(.=$var1)]"&gt;
                  &lt;xsl:value-of select="$xinput/root/section/sub-section/chapter"/&gt;
              &lt;/xsl:for-each&gt;
  
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Current HTML output:</p>
  
  <pre><code>Chapter1 Chapter2
  </code></pre>
  
  <p>My desired HTML output is to get the text:</p>
  
  <pre><code>Chapter1
  </code></pre>
  
  <p>from the sub-section node <code>if Author1A (from XML1 file) = Author 1A (from XML2 file)</code></p>
  
  <p>What i am getting now is a list of all Chapters. how can I just get Chapter1?</p>