title: BizTalk Map, Prevent Looping For-Each
body: <p>In the source XSD of the following map, InvTransTable and ToWarehouse elements are unbounded.</p>
  
  <p>I want to map values only for the first iteration in each case. My problem is, the XSLT generated by the map contains two loops, as can be seen in the following:</p>
  
  <pre><code>&lt;ns0:Record&gt;
          &lt;xsl:for-each select="s1:InvTransTable"&gt;
            &lt;xsl:variable name="var:v4" select="position()" /&gt;
            &lt;xsl:for-each select="s1:ToWarehouse"&gt;
              &lt;xsl:variable name="var:v5" select="position()" /&gt;
              &lt;xsl:variable name="var:v6" select="userCSharp:LogicalEq(string($var:v5) , &amp;quot;1&amp;quot;)" /&gt;
              &lt;xsl:variable name="var:v7" select="userCSharp:LogicalEq(string($var:v4) , &amp;quot;1&amp;quot;)" /&gt;
              &lt;xsl:variable name="var:v8" select="userCSharp:LogicalAnd(string($var:v6) , string($var:v7))" /&gt;
              &lt;xsl:variable name="var:v12" select="userCSharp:StringUpperCase(&amp;quot;B&amp;quot;)" /&gt;
              &lt;xsl:variable name="var:v13" select="userCSharp:StringUpperCase(&amp;quot;M&amp;quot;)" /&gt;
              &lt;xsl:variable name="var:v14" select="userCSharp:StringUpperCase(&amp;quot;4&amp;quot;)" /&gt;
              &lt;ns0:Header&gt;
                &lt;xsl:if test="string($var:v8)='true'"&gt;
                  &lt;xsl:variable name="var:v9" select="s1:EXDRefCustAccount/text()" /&gt;
                  &lt;ns0:AccountNo&gt;
                    &lt;xsl:value-of select="$var:v9" /&gt;
                  &lt;/ns0:AccountNo&gt;
                &lt;/xsl:if&gt;
                &lt;xsl:if test="string($var:v7)='true'"&gt;
                  &lt;xsl:variable name="var:v10" select="../s1:ShipDate/text()" /&gt;
                  &lt;ns0:DateExpected&gt;
                    &lt;xsl:value-of select="$var:v10" /&gt;
                  &lt;/ns0:DateExpected&gt;
                &lt;/xsl:if&gt;
  </code></pre>
  
  <p>This results in the created XML containing multiple header elements, which is not what I want!</p>
  
  <p>I've tried to prevent this throug the use of Iteration (checking for a value of 1) and Conditional functoids but this hasn't worked. Can anyone please advise how I can achieve what is needed without resorting to a scripting functoid or replacing the map with XSLT?</p>
  
  <p><img src="https://i.stack.imgur.com/3HAlY.png" alt="enter image description here"></p>