Rob Bowman
Rob Bowman

Reputation: 8701

BizTalk Map, Prevent Looping For-Each

In the source XSD of the following map, InvTransTable and ToWarehouse elements are unbounded.

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:

<ns0:Record>
        <xsl:for-each select="s1:InvTransTable">
          <xsl:variable name="var:v4" select="position()" />
          <xsl:for-each select="s1:ToWarehouse">
            <xsl:variable name="var:v5" select="position()" />
            <xsl:variable name="var:v6" select="userCSharp:LogicalEq(string($var:v5) , &quot;1&quot;)" />
            <xsl:variable name="var:v7" select="userCSharp:LogicalEq(string($var:v4) , &quot;1&quot;)" />
            <xsl:variable name="var:v8" select="userCSharp:LogicalAnd(string($var:v6) , string($var:v7))" />
            <xsl:variable name="var:v12" select="userCSharp:StringUpperCase(&quot;B&quot;)" />
            <xsl:variable name="var:v13" select="userCSharp:StringUpperCase(&quot;M&quot;)" />
            <xsl:variable name="var:v14" select="userCSharp:StringUpperCase(&quot;4&quot;)" />
            <ns0:Header>
              <xsl:if test="string($var:v8)='true'">
                <xsl:variable name="var:v9" select="s1:EXDRefCustAccount/text()" />
                <ns0:AccountNo>
                  <xsl:value-of select="$var:v9" />
                </ns0:AccountNo>
              </xsl:if>
              <xsl:if test="string($var:v7)='true'">
                <xsl:variable name="var:v10" select="../s1:ShipDate/text()" />
                <ns0:DateExpected>
                  <xsl:value-of select="$var:v10" />
                </ns0:DateExpected>
              </xsl:if>

This results in the created XML containing multiple header elements, which is not what I want!

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?

enter image description here

Upvotes: 0

Views: 2122

Answers (1)

BizTalkMama
BizTalkMama

Reputation: 308

If you know you only need to map the first instance of each, use the Index functoid with an index of 1, instead of the Iteration functoid.

Upvotes: 2

Related Questions