locked
BizTalk Map looping not doing correctly RRS feed

  • Question

  • My requirement is in Source schema check if ItemID (under SerialNumber) = ItemID(Detail)

    If equal, generate some fields from each of these Detail and SerialNumber

    records into Output. When I used Equal Functoid, only its checking for 1

    ItemID and skipping all others...I used Looping functoid too but not

    getting required output. How should this be done ? Any inputs please

    Source Schema : XML file <ns0:Detail> <ns0:ItemId>11000017040</ns0:ItemId> <ns0:QuantityShipped>2.00</ns0:QuantityShipped> <ns0:SiteId>US-01</ns0:SiteId> </ns0:Detail> <ns0:Detail> <ns0:ItemId>11000019912</ns0:ItemId> <ns0:QuantityShipped>1.00</ns0:QuantityShipped> <ns0:SiteId>US-01</ns0:SiteId> </ns0:Detail> <ns0:SerialNumbers> <ns0:ItemId>11000019912</ns0:ItemId> <ns0:IMEINumber>359893050780571</ns0:IMEINumber> </ns0:SerialNumbers> <ns0:SerialNumbers> <ns0:ItemId>11000017040</ns0:ItemId> <ns0:IMEINumber>359893050781868</ns0:IMEINumber> </ns0:SerialNumbers> <ns0:SerialNumbers> <ns0:ItemId>11000017040</ns0:ItemId> <ns0:IMEINumber>359893050841688</ns0:IMEINumber> </ns0:SerialNumbers> </ns0:Shipment> Destination schema : <?xml version="1.0" encoding="utf-16" ?> - <xs:schema xmlns="http://CompanyName.Integration.Test.Schema1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://CompanyName.Integration.Test.Schema1" xmlns:xs="http://www.w3.org/2001/XMLSchema"> - <xs:element name="Shipment"> - <xs:complexType> - <xs:sequence> - <xs:element maxOccurs="unbounded" name="SNumbers"> - <xs:complexType> - <xs:sequence> <xs:element name="IMEINumber" type="xs:string" /> <xs:element name="PackingSlipID" type="xs:string" /> <xs:element name="QTY" type="xs:string" /> <xs:element name="ItemID" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>



    MBH



    • Edited by JaguarsJag Wednesday, May 27, 2015 4:14 PM info
    Wednesday, May 27, 2015 4:13 PM

Answers

  • Here you go. This should help you.

    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:s0="http://Brightstar.Integration.LATAM.Shipments.Schemas.Shipment.1000" xmlns:ns0="http://Brightstar.Integration.LATAM.SamsungCollaboration.ItemIDs">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
      <xsl:template match="/">
        <xsl:apply-templates select="/s0:Shipment" />
      </xsl:template>
      <xsl:template match="/s0:Shipment">
        <ns0:Shipments>
          <xsl:for-each select="s0:Detail">
            <xsl:variable name="itemId" select="s0:ItemId/text()"></xsl:variable>
            <xsl:variable name="Warehouse" select="s0:Warehouse/text()"></xsl:variable>
            <xsl:for-each select="../s0:SerialNumbers">
              
              <xsl:if test="$itemId=s0:ItemId/text()">
                <ItemIdRecord>
                  <WareHouse>
                    <xsl:value-of select="$Warehouse" />
                  </WareHouse>
                  <ItemId>
                  <xsl:value-of select="s0:ItemId"/>
                  </ItemId>
                  <IMEINumber>
                    <xsl:value-of select="s0:IMEINumber/text()" />
                  </IMEINumber>
                </ItemIdRecord>
              </xsl:if>
              
            </xsl:for-each>
          </xsl:for-each>
        </ns0:Shipments>
      </xsl:template>
    </xsl:stylesheet>


    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Marked as answer by JaguarsJag Thursday, May 28, 2015 5:27 PM
    Thursday, May 28, 2015 4:19 PM

All replies

  • I am receiving the below output, but I wanted output with records having only ItemId field in it. The record without matching ItemId should be ignored.

    I applied a equalTo functoid and a loop functoid, but additional records are being populated. How can that be ignored ?

    ns0:Shipments xmlns:ns0="http://Company.Integration.Test.Schemas">
     <ItemIdRecord>
      <WareHouse>14009</WareHouse> 
      <IMEINumber>359893050780571</IMEINumber> 
      </ItemIdRecord>
    
     <ItemIdRecord>
      <WareHouse>14009</WareHouse> 
      <IMEINumber>359893050780571</IMEINumber> 
      </ItemIdRecord>
    
     <ItemIdRecord>
      <WareHouse>14009</WareHouse> 
      <ItemId>11000019912</ItemId> 
      <IMEINumber>359893050780571</IMEINumber> 
      </ItemIdRecord>
    
     <ItemIdRecord>
      <WareHouse>14009</WareHouse> 
      <ItemId>11000017040</ItemId> 
      <IMEINumber>359893050781868</IMEINumber> 
      </ItemIdRecord>
    
     <ItemIdRecord>
      <WareHouse>14009</WareHouse> 
      <ItemId>11000017040</ItemId> 
      <IMEINumber>359893050841688</IMEINumber> 
      </ItemIdRecord>
      </ns0:Shipments>



    MBH

    Wednesday, May 27, 2015 9:30 PM
  • apart from XSLT, is there anyway this can be achieved with out of box functionality ?

    MBH

    Thursday, May 28, 2015 2:30 AM
  • XSLT is efficient for this...Otherwise you can achieve this using a combination of functoids valuemapping,logicaleq and cumulative.

    Cheers


    JB

    Thursday, May 28, 2015 3:51 AM
  • Can you please give an example for the above scenario ? First preference is using functoids you mentioned, how can I apply in my map for elements mentioned above in schema ? 2) also iam new to xslt, can you provide xslt code for the same to acheive ?

    MBH

    Thursday, May 28, 2015 8:07 AM
  • below is the Map, I want output xml if only ItemId element in Detail matches with ItemId element in SerialNumbers, else ignore the record.

    Above is provided with source xml file also in previous converstion

    when I do the above Map, receiving below output. The first and 2nd record does not have matching ItemId but is still populating. I want the

    output only with records 3,4,5 and ignore 1 and 2.

    <ns0:Shipments xmlns:ns0="http://Company.Integration.Test.Schemas"> <ItemIdRecord> <WareHouse>14009</WareHouse> <IMEINumber>359893050780571</IMEINumber> </ItemIdRecord> <ItemIdRecord> <WareHouse>14009</WareHouse> <IMEINumber>359893050780571</IMEINumber> </ItemIdRecord> <ItemIdRecord> <WareHouse>14009</WareHouse> <ItemId>11000019912</ItemId> <IMEINumber>359893050780571</IMEINumber> </ItemIdRecord> <ItemIdRecord> <WareHouse>14009</WareHouse> <ItemId>11000017040</ItemId> <IMEINumber>359893050781868</IMEINumber> </ItemIdRecord> <ItemIdRecord> <WareHouse>14009</WareHouse> <ItemId>11000017040</ItemId> <IMEINumber>359893050841688</IMEINumber> </ItemIdRecord> </ns0:Shipments>



    MBH



    • Edited by JaguarsJag Thursday, May 28, 2015 8:57 AM info
    Thursday, May 28, 2015 8:52 AM
  • Could you email me your schemas and map to ravindar.thati@gmail.com

    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    Thursday, May 28, 2015 9:53 AM
  • Here you go. This should help you.

    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:s0="http://Brightstar.Integration.LATAM.Shipments.Schemas.Shipment.1000" xmlns:ns0="http://Brightstar.Integration.LATAM.SamsungCollaboration.ItemIDs">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
      <xsl:template match="/">
        <xsl:apply-templates select="/s0:Shipment" />
      </xsl:template>
      <xsl:template match="/s0:Shipment">
        <ns0:Shipments>
          <xsl:for-each select="s0:Detail">
            <xsl:variable name="itemId" select="s0:ItemId/text()"></xsl:variable>
            <xsl:variable name="Warehouse" select="s0:Warehouse/text()"></xsl:variable>
            <xsl:for-each select="../s0:SerialNumbers">
              
              <xsl:if test="$itemId=s0:ItemId/text()">
                <ItemIdRecord>
                  <WareHouse>
                    <xsl:value-of select="$Warehouse" />
                  </WareHouse>
                  <ItemId>
                  <xsl:value-of select="s0:ItemId"/>
                  </ItemId>
                  <IMEINumber>
                    <xsl:value-of select="s0:IMEINumber/text()" />
                  </IMEINumber>
                </ItemIdRecord>
              </xsl:if>
              
            </xsl:for-each>
          </xsl:for-each>
        </ns0:Shipments>
      </xsl:template>
    </xsl:stylesheet>


    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

    • Marked as answer by JaguarsJag Thursday, May 28, 2015 5:27 PM
    Thursday, May 28, 2015 4:19 PM
  • Hi Ravinder - I have further questions related to XSLT ?

    MBH

    Monday, October 24, 2016 2:53 PM