0
votes

I am pretty new to writing custom XML for the Biztalk mapper and I am running into an issue with a nested loop that I need to make.

   <xsl:for-each select="customers">
    <xsl:for-each select="customer">
      <xsl:variable name="var:v9" select="'BY'" />
      <xsl:variable name="var:v10" select="@name" />
      <xsl:variable name="var:v11" select="'91'" />
      <xsl:variable name="var:v12" select="@accountNumber" />
      <ns0:N1Loop1>
        <ns0:N1>
          <N101>
            <xsl:value-of select="$var:v9" />
          </N101>
          <N102>
            <xsl:value-of select="$var:v10" />
          </N102>
          <N103>
            <xsl:value-of select="$var:v11" />
          </N103>
          <N104>
            <xsl:value-of select="$var:v12" />
          </N104>
        </ns0:N1>
      </ns0:N1Loop1>
      <xsl:for-each select="products">
        <xsl:for-each select="product">
          <xsl:variable name="var:v13" select="'VC'" />
          <xsl:variable name="var:v14" select="@sku" />
          <xsl:variable name="var:v15" select="'003'" />
          <xsl:variable name="var:v16" select="'208'" />
          <xsl:variable name="var:v17" select="@expirationDate" />
          <xsl:variable name="var:v19" select="'F'" />
          <xsl:variable name="var:v20" select="'RX'" />
          <xsl:variable name="var:v21" select="@description" />
          <xsl:variable name="var:v22" select="@caseSize" />
          <xsl:variable name="var:v23" select="@size" />
          <xsl:variable name="var:v24" select="'EA'" />
          <xsl:variable name="var:v25" select="'INV'" />
          <xsl:variable name="var:v26" select="@unitPrice" />
          <xsl:variable name="var:v27" select="'MF'" />
          <xsl:variable name="var:v28" select="@manufacturerName" />
          <ns0:LINLoop1>
            <ns0:LIN>
              <LIN02>
                <xsl:value-of select="$var:v13" />
              </LIN02>
              <LIN03>
                <xsl:value-of select="$var:v14" />
              </LIN03>
            </ns0:LIN>
            <ns0:G53>
              <G5301>
                <xsl:value-of select="$var:v15" />
              </G5301>
            </ns0:G53>
            <ns0:DTM_4>
              <DTM01>
                <xsl:value-of select="$var:v16" />
              </DTM01>
              <xsl:variable name="var:v18" select="userCSharp:ConvertDate(string($var:v17))" />
              <DTM02>
                <xsl:value-of select="$var:v18" />
              </DTM02>
            </ns0:DTM_4>
            <ns0:PID>
              <PID01>
                <xsl:value-of select="$var:v19" />
              </PID01>
              <PID02>
                <xsl:value-of select="$var:v20" />
              </PID02>
              <PID05>
                <xsl:value-of select="$var:v21" />
              </PID05>
            </ns0:PID>
            <ns0:PO4>
              <PO401>
                <xsl:value-of select="$var:v22" />
              </PO401>
              <PO402>
                <xsl:value-of select="$var:v23" />
              </PO402>
              <PO403>
                <xsl:value-of select="$var:v24" />
              </PO403>
            </ns0:PO4>
            <ns0:CTPLoop1>
              <ns0:CTP_2>
                <CTP02>
                  <xsl:value-of select="$var:v25" />
                </CTP02>
                <CTP03>
                  <xsl:value-of select="$var:v26" />
                </CTP03>
              </ns0:CTP_2>
            </ns0:CTPLoop1>
            <ns0:N1Loop2>
              <ns0:N1_2>
                <N101>
                  <xsl:value-of select="$var:v27" />
                </N101>
                <N102>
                  <xsl:value-of select="$var:v28" />
                </N102>
              </ns0:N1_2>
            </ns0:N1Loop2>
          </ns0:LINLoop1>
        </xsl:for-each>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:for-each>

I made a for-each to locate the customer fields in an N1Loop1 and then followed by doing for-each to a LINLoop1 to go through each of the products right under the N1 fields. When I use this code I get the following error:

Error btm1046: Output validation error: The element 'X12_00401_832' in namespace 'http://schemas.microsoft.com/BizTalk/EDI/X12/2006' has invalid child element 'N1Loop1' in namespace 'http://schemas.microsoft.com/BizTalk/EDI/X12/2006'. List of possible elements expected: 'LINLoop1, CTT' in namespace 'http://schemas.microsoft.com/BizTalk/EDI/X12/2006' as well as 'SE'.

Can someone point me in the right direction. All help appreciated.

1
Is the N1Loop1 node correctly positioned within the output file? Open the output schema to verify where it should appear.Jay

1 Answers

0
votes

If you are generating multiple x12 data based on each customer, make sure to add these nodes CTT and SE after foreach loop. This is based on X12_00603_832 EDI validation requirement.

<foreach> <customer>
   <foreach><n1loop1></foreach>
   <foreach><linloop1></foreach>          
   <CTT>        
     <CTT01>23</CTT01>
   </CTT>
   <SE>
    <SE01>154</SE01>
    <SE02>ST02</SE02>
   </SE> </customer></foreach>