title: Biztalk two schemas and loop functoid with condition
body: <p>How to create mapping when on input we will have two schema's and on output will be one schema and some condition across mapping ?</p>
  
  <p>Input is an inline schema and contains Invoices and Customers schema's.
  Both of them have CustomerNumber and DepartmentCode exist only on Invoices schema.</p>
  
  <p><strong>[CONDITION]</strong></p>
  
  <p><em>Mapp only this <strong>DepartmentCode</strong> if <strong>CustomerNumber</strong> is same on both Invoice and Customer data (line)</em>.</p>
  
  <pre><code>If Invoice.CustomerNumber == Customer.CustomerNumber then map Invoice.DepartmentCode.
  </code></pre>
  
  <p>I've tried to use <a href="https://msdn.microsoft.com/en-us/library/aa559012.aspx" rel="nofollow noreferrer">loop</a>, equal and value mapping functoid's but without expected results,
  second think I've tried to use "Inline xslt call template" but I've got an error on processing.</p>
  
  <p><strong>[Code of XSLT functoid]</strong></p>
  
  <pre><code>&lt;xsl:template name="GetDepartmenCodeByCustomerNumber"&gt;
      &lt;xsl:param name="CustomerNumber" /&gt;
      &lt;xsl:if test="$CustomerNumber != ''"&gt;
          &lt;xsl:element name="DepartmentCode"&gt;
              &lt;xsl:value-of select="//s1:Customer[s1:CustomerNumber=$CustomerNumber]/s1:DepartmentCode/text()" /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Example:</p>
  
  <p><strong>Input</strong></p>
  
  <pre><code>&lt;ROOT&gt;
   &lt;Invoices&gt;
    &lt;Invoice&gt;
     &lt;CustomerNumber&gt;123&lt;/CustomerNumber&gt;
     &lt;DepartmentCode&gt;321&lt;/DepartmentCode&gt;
    &lt;/Invoice&gt;
   &lt;/Invoices&gt;
   &lt;Customers&gt;
    &lt;Customer&gt;
     &lt;CustomerNumber&gt;123&lt;/CustomerNumber&gt;
    &lt;/Customer&gt;
    &lt;Customer&gt;
     &lt;CustomerNumber&gt;222&lt;/CustomerNumber&gt;
    &lt;/Customer&gt;
   &lt;/Customers&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p><strong>Expect</strong></p>
  
  <pre><code>&lt;Document&gt;
   &lt;CustomerNumber&gt;123&lt;/CustomerNumber&gt;
   &lt;DepartmentCode&gt;321&lt;/DepartmentCode&gt;
  &lt;/Document&gt;
  </code></pre>
  
  <p>For example I need to equal CustomerNumber from Invoice and Customer segment.</p>