multiple source mapping issue

Home Page Forums BizTalk 2004 – BizTalk 2010 multiple source mapping issue

Viewing 2 reply threads
  • Author
    Posts
    • #22533

      Hi,

      I have multiple sources in BizTalk that needs to be mapped out to a destination system. I tried few options and looping functoid but could not achieve what I am trying to do. Hope someone can help. Here is the scenario:

      I have customer information that resides into two different databases and after pulling customer information from both databases, I need to take few fields from customer info from database1 and customer info from database2 and put it into destination system by matching common CustomerID field.

      Example:

      xml generated from database 1:
      ——————————————-

      <ns0:Customers xmlns:ns0=http://SQL_Send_Receive_Adapter.CustomerName>
        <Customer>
          <CustomerID>2</CustomerID>
          <Name>xxxx</Name>
        <Customer>

        <Customer>
          <CustomerID>1</CustomerID>
          <Name>xxxx</Name>
        <Customer>

      </ns0:Customers>

      xml generated from database 2:
      ——————————————

      <ns2:Customers xmlns:ns0=”http://SQL_Send_Receive_Adapter.CustomerPhone“>
        <Customer>
          <CustomerID>1</CustomerID>
          <Phone>222-2222</Phone>
        </Customer>
        <Customer>
          <CustomerID>2</CustomerID>
          <Phone>333-3333</Phone>
        </Customer>
        <Customer>
          <CustomerID>7</CustomerID>
          <Phone>444444</Phone>
        </Customer>
        <Customer>
          <CustomerID>9</CustomerID>
          <Phone>444444</Phone>
        </Customer>
      </ns2:Customers>

       Destination System (Merge customer info from Database1 and Database2 that matches CustomerID):
      ———————————————————————————————–

       <ns3:Customers xmlns:ns0=http://SQL_Send_Receive_Adapter.Customer>
        <Customer>
          <CustomerID>2</CustomerID>
          <Name>xxx</Name>
          <Phone>222-2222</Phone>
        </Customer>
        <Customer>
          <CustomerID>1</CustomerID>
          <Name>xxx</Name>
          <Phone>333-3333</Phone>
        </Customer>
      </ns3:Customers>

      Any idea how to achieve this?

       

      Thanks,

      andy

    • #22534

       

       

       

      Hi, You can use a custom XSL for your map. here is an example:

      1. I created the following input schemas:

       

      <?xml version=”1.0″ encoding=”utf-16″?>
      <xs:schema xmlns:b=”http://schemas.microsoft.com/BizTalk/2003&#8243; xmlns=”http://BizTalk_Server_Project1.CustomerName&#8221; targetNamespace=”http://BizTalk_Server_Project1.CustomerName&#8221; xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;
       <xs:element name=”Customers”>
         <xs:complexType>
           <xs:sequence>
             <xs:element maxOccurs=”unbounded” name=”Customer”>
               <xs:complexType>
                 <xs:sequence>
                   <xs:element name=”CustomerID” type=”xs:string” />
                   <xs:element name=”Name” type=”xs:string” />
                 </xs:sequence>
               </xs:complexType>
             </xs:element>
           </xs:sequence>
         </xs:complexType>
       </xs:element>
      </xs:schema>

      ——————————————

       

      <?xml version=”1.0″ encoding=”utf-16″?>
      <xs:schema xmlns:b=”http://schemas.microsoft.com/BizTalk/2003&#8243; xmlns=”http://BizTalk_Server_Project1.CustomerPhone&#8221; targetNamespace=”http://BizTalk_Server_Project1.CustomerPhone&#8221; xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;
       <xs:element name=”Customers”>
         <xs:complexType>
           <xs:sequence>
             <xs:element maxOccurs=”unbounded” name=”Customer”>
               <xs:complexType>
                 <xs:sequence>
                   <xs:element name=”CustomerID” type=”xs:string” />
                   <xs:element name=”PhoneNumber” type=”xs:string” />
                 </xs:sequence>
               </xs:complexType>
             </xs:element>
           </xs:sequence>
         </xs:complexType>
       </xs:element>
      </xs:schema>

      ——————————————-

      The destination schema is as such:

       

      <?xml version=”1.0″ encoding=”utf-16″?>
      <xs:schema xmlns:b=”http://schemas.microsoft.com/BizTalk/2003&#8243; xmlns=”http://BizTalk_Server_Project1.CustomerRecord&#8221; targetNamespace=”http://BizTalk_Server_Project1.CustomerRecord&#8221; xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;
       <xs:element name=”Customers”>
         <xs:complexType>
           <xs:sequence>
             <xs:element maxOccurs=”unbounded” name=”Customer”>
               <xs:complexType>
                 <xs:sequence>
                   <xs:element name=”CustomerID” type=”xs:string” />
                   <xs:element name=”Name” type=”xs:string” />
                   <xs:element name=”PhoneNumber” type=”xs:string” />
                 </xs:sequence>
               </xs:complexType>
             </xs:element>
           </xs:sequence>
         </xs:complexType>
       </xs:element>
      </xs:schema>

      —————————————————–

      The map is setup to use a custom XSLT file:

      ——————————————————-

      here is the test input data:

      <ns0:Root xmlns:ns0=”http://schemas.microsoft.com/BizTalk/2003/aggschema”&gt;
       <InputMessagePart_0>
         <ns1:Customers xmlns:ns1=”http://BizTalk_Server_Project1.CustomerName”&gt;
           <Customer>
             <CustomerID>CustomerID_0</CustomerID>
             <Name>Name_0</Name>
           </Customer>
           <Customer>
             <CustomerID>CustomerID_1</CustomerID>
             <Name>Name_1</Name>
           </Customer>
           <Customer>
             <CustomerID>CustomerID_11</CustomerID>
             <Name>Name_11</Name>
           </Customer>
         </ns1:Customers>
       </InputMessagePart_0>
       <InputMessagePart_1>
         <ns2:Customers xmlns:ns2=”http://BizTalk_Server_Project1.CustomerPhone”&gt;
           <Customer>
             <CustomerID>CustomerID_0</CustomerID>
             <PhoneNumber>PhoneNumber_0</PhoneNumber>
           </Customer>
           <Customer>
             <CustomerID>CustomerID_1</CustomerID>
             <PhoneNumber>PhoneNumber_1</PhoneNumber>
           </Customer>
           <Customer>
             <CustomerID>CustomerID_2</CustomerID>
             <PhoneNumber>PhoneNumber_2</PhoneNumber>
           </Customer>
         </ns2:Customers>
       </InputMessagePart_1>
      </ns0:Root>

       

      —————————-

      and here is the actual custom XSL file:

      <?xml version=”1.0″ encoding=”UTF-8″?>
      <xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221; xmlns:msxsl=”urn:schemas-microsoft-com:xslt” xmlns:var=”http://schemas.microsoft.com/BizTalk/2003/var&#8221; exclude-result-prefixes=”msxsl var s2 s0 s1 userCSharp” version=”1.0″ xmlns:s2=”http://schemas.microsoft.com/BizTalk/2003/aggschema&#8221; xmlns:ns0=”http://BizTalk_Server_Project1.CustomerRecord&#8221; xmlns:s0=”http://BizTalk_Server_Project1.CustomerPhone&#8221; xmlns:s1=”http://BizTalk_Server_Project1.CustomerName&#8221; xmlns:userCSharp=”http://schemas.microsoft.com/BizTalk/2003/userCSharp”&gt;
       <xsl:output omit-xml-declaration=”yes” method=”xml” version=”1.0″ />
       <xsl:template match=”/”>
         <xsl:apply-templates select=”/s2:Root” />
       </xsl:template>
       <xsl:template match=”/s2:Root”>
         <ns0:Customers>
           <xsl:variable name=”var:namecount” select=”count(InputMessagePart_0/s1:Customers/Customer)” />
           <xsl:variable name=”var:phonecount” select=”count(InputMessagePart_1/s0:Customers/Customer)” />
           <xsl:call-template name=”loopName”>
            <xsl:with-param name=”index”>1</xsl:with-param>
            <xsl:with-param name=”ncount”><xsl:value-of select=”$var:namecount” /></xsl:with-param>
            <xsl:with-param name=”pcount”><xsl:value-of select=”$var:phonecount” /></xsl:with-param>
            <xsl:with-param name=”id”><xsl:value-of select=”string(InputMessagePart_0/s1:Customers/Customer[1]/CustomerID/text())” /></xsl:with-param>
            <xsl:with-param name=”name”><xsl:value-of select=”string(InputMessagePart_0/s1:Customers/Customer[1]/Name/text())” /></xsl:with-param>
           </xsl:call-template>    

         </ns0:Customers>
       </xsl:template>
      <xsl:template name=”loopName”>
       <xsl:param name=”index” />
       <xsl:param name=”ncount” />
       <xsl:param name=”pcount” />
       <xsl:param name=”id” />
       <xsl:param name=”name” />
       <xsl:if test=”$index &lt;= $ncount” >
       <xsl:call-template name=”loopPhone”>
        <xsl:with-param name=”pindex”>1</xsl:with-param>
        <xsl:with-param name=”ppcount”>
         <xsl:value-of select=”$pcount” />
        </xsl:with-param>
        <xsl:with-param name=”cname”>
         <xsl:value-of select=”$name” />
        </xsl:with-param>
        <xsl:with-param name=”nid”>
         <xsl:value-of select=”$id” />
        </xsl:with-param>
               <xsl:with-param name=”pid”><xsl:value-of select=”string(InputMessagePart_1/s0:Customers/Customer[1]/CustomerID/text())” /></xsl:with-param>
               <xsl:with-param name=”phone”><xsl:value-of select=”string(InputMessagePart_1/s0:Customers/Customer[1]/PhoneNumber/text())” /></xsl:with-param>
       </xsl:call-template>
       </xsl:if>
       <xsl:if test=”$index &lt;= $ncount” >
       <xsl:call-template name=”loopName”>
        <xsl:with-param name=”index”>
         <xsl:value-of select=”$index + 1″ />
        </xsl:with-param>
        <xsl:with-param name=”ncount”>
         <xsl:value-of select=”$ncount” />
        </xsl:with-param>
        <xsl:with-param name=”pcount”>
         <xsl:value-of select=”$pcount” />
        </xsl:with-param>
               <xsl:with-param name=”id”><xsl:value-of select=”string(InputMessagePart_0/s1:Customers/Customer[$index+1]/CustomerID/text())” /></xsl:with-param>
               <xsl:with-param name=”name”><xsl:value-of select=”string(InputMessagePart_0/s1:Customers/Customer[$index+1]/Name/text())” /></xsl:with-param>
       </xsl:call-template>
       </xsl:if>
      </xsl:template>
      <xsl:template name=”loopPhone”>
       <xsl:param name=”pindex” />
       <xsl:param name=”ppcount” />
       <xsl:param name=”cname” />
       <xsl:param name=”nid” />
       <xsl:param name=”pid” />
       <xsl:param name=”phone” />
       <xsl:if test=”$pindex &lt;= $ppcount” >
       <xsl:variable name=”var:v3″ select=”userCSharp:LogicalEq($pid , $nid)” />
       <xsl:if test=”$var:v3″>
         <Customer>
           <CustomerID>
             <xsl:value-of select=”$nid” />
           </CustomerID>
           <Name>
             <xsl:value-of select=”$cname” />
           </Name>
           <PhoneNumber>
             <xsl:value-of select=”$phone” />
           </PhoneNumber>
         </Customer>
       </xsl:if>
       </xsl:if>
       <xsl:if test=”$pindex &lt;= $ppcount” >
       <xsl:call-template name=”loopPhone”>
        <xsl:with-param name=”pindex”>
         <xsl:value-of select=”$pindex + 1″ />
        </xsl:with-param>
        <xsl:with-param name=”ppcount”>
         <xsl:value-of select=”$ppcount” />
        </xsl:with-param>
        <xsl:with-param name=”cname”>
         <xsl:value-of select=”$cname” />
        </xsl:with-param>
        <xsl:with-param name=”nid”>
         <xsl:value-of select=”$nid” />
        </xsl:with-param>
               <xsl:with-param name=”pid”><xsl:value-of select=”string(InputMessagePart_1/s0:Customers/Customer[$pindex+1]/CustomerID/text())” /></xsl:with-param>
               <xsl:with-param name=”phone”><xsl:value-of select=”string(InputMessagePart_1/s0:Customers/Customer[$pindex+1]/PhoneNumber/text())” /></xsl:with-param>
       </xsl:call-template>
       </xsl:if>
       

       

      </xsl:template>
       <msxsl:script language=”C#” implements-prefix=”userCSharp”><![CDATA[

       

      public bool LogicalEq(string val1, string val2)

      {

       bool ret = false;

       

       double d1 = 0;

       

       double d2 = 0;

       

       if (IsNumeric(val1, ref d1) && IsNumeric(val2, ref d2))

       

       {

       

       ret = d1 == d2;

       

       }

       

       else

       

       {

       

       ret = String.Compare(val1, val2, StringComparison.Ordinal) == 0;

       

       }

       

       return ret;

       

      }

       

       

      public bool IsNumeric(string val)

      {

       if (val == null)

       

       {

       

       return false;

       

       }

       

       double d = 0;

       

       return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);

       

      }

       

      public bool IsNumeric(string val, ref double d)

      {

       if (val == null)

       

       {

       

       return false;

       

       }

       

       return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);

       

      }

       

       

      ]]></msxsl:script>
      </xsl:stylesheet>

       

      —————————–

      Hope this helps

       

       

      • #22538

        Thanks Guo Ming Li!

        Do you have sample project for this by any chance that you can email it to me? Also, do you use any tool to generate xslt?

        • #22540

          Sure, can you please give me your email address?

          I was just using Visual Studio to genenerate the XSLT. However there’s a trick of doing this though. After setting up the BTM (map) file, simply map one of the field from source schema to any field of destination schema. Then you right click on the BTM field in the “Solution Explorer” and choose “Validate Map”, then you should be able to see some mesage in the “Output” view. In the “Output” view, you should be able to see a link to the output XSLT generated base on the map file.

          Hope this helps.

          • #22543

            [email protected]

             

            Thanks!

          • #22735

            Can you also mail me the sample project too ( [email protected]).

            Thanks,

            Matt

            • #22739

              Sent. 🙂

              • #22941

                My xml file is like this :

                <ns0:Employee xmlns:ns0=”http://PrimaryFile.EmployeeDocument>

                <Employee>
                  <Org_Code>31-29-00-0000-00</Org_Code>
                  <FIRST_NAME>Sam</FIRST_NAME>
                  <LAST-NAME />
                  <MI>M</MI>
                  <TITLE>PUBLIC AFF SPECLST(REGIONAL COMM DIR)</TITLE>
                  <PP>GS</PP>
                  <Series>1032</Series>
                  <GR>12</GR>
                  <Step>1</Step>
                  <PD>A0212001</PD>
                  <User_Role>1</User_Role>
                  <Email_Adress>uop.com</Email_Adress>
                  <PrimarySupervisor>[email protected]</PrimarySupervisor>
                  <SecondarySupervisor>[email protected]</SecondarySupervisor>
                  <Status><BR>Orgcode is not given</BR> <BR>Invalid email passed</BR></Status>
                  </Employee>
                <Employee>
                  <Org_Code>31-29-00-0000-00</Org_Code>
                  <FIRST_NAME>Rutu3221vdfbdfgdggggghsdfsdf</FIRST_NAME>
                  <LAST-NAME>kjooijei</LAST-NAME>
                  <MI>t</MI>
                  <TITLE>PUBLIC AFF T(REGIONAL COMM DIR)</TITLE>
                  <PP>GS</PP>
                  <Series>1032</Series>
                  <GR>12</GR>
                  <Step>1</Step>
                  <PD>A0212001</PD>
                  <User_Role>1</User_Role>
                  <Email_Adress>[email protected]</Email_Adress>
                  <PrimarySupervisor>[email protected]</PrimarySupervisor>
                  <SecondarySupervisor>[email protected]</SecondarySupervisor>
                  <Status><BR>First Name is very large</BR> <BR>Last Name is very large</BR> <BR>Invalid email passed</BR></Status>
                  </Employee>
                <Employee>
                  <Org_Code />
                  <FIRST_NAME />
                  <LAST-NAME />
                  <MI />
                  <TITLE />
                  <PP />
                  <Series />
                  <GR />
                  <Step />
                  <PD />
                  <User_Role />
                  <Email_Adress />
                  <PrimarySupervisor />
                  <SecondarySupervisor />
                  <Status><BR>First Name is not passed</BR> <BR>Orgcode is not given</BR> <BR>Last Name is not passed </BR> <BR>Email id is not passed</BR></Status>
                  </Employee>
                <Employee>
                  <Org_Code>31-29-00-0000-00</Org_Code>
                  <FIRST_NAME>Sam</FIRST_NAME>
                  <LAST-NAME />
                  <MI>M</MI>
                  <TITLE>PUBLIC AFF SPECLST(REGIONAL COMM DIR)</TITLE>
                  <PP>GS</PP>
                  <Series>1032</Series>
                  <GR>12</GR>
                  <Step>1</Step>
                  <PD>A0212001</PD>
                  <User_Role>1</User_Role>
                  <Email_Adress>c.com</Email_Adress>
                  <PrimarySupervisor>[email protected]</PrimarySupervisor>
                  <SecondarySupervisor>[email protected]</SecondarySupervisor>
                  <Status><BR>Orgcode is not given</BR> <BR>Invalid email passed</BR></Status>
                  </Employee>
                  </ns0:Employee>
                i want to check for dupluicate entries inxml file based on email address suplied can u suggest me how to do so?
                • #23111

                  Here is am example: input xml file has duplicate records, XSLT will remove duplicate and output a single instance of duplicate records only (base on UserID as a key)

                  —————————————–

                  here is the sample XML

                  —————————————–

                  <ns0:Employees xmlns:ns0=”http://BizTalk_Server_Project1.Employees”&gt;

                  <Employee>

                    <FirstName>FirstName_0</FirstName> 

                    <LastName>LastName_0</LastName> 

                    <RecordID>RecordID_0</RecordID> 

                    <UserID>UserID_0</UserID> 

                    <Address>Address_0</Address> 

                    </Employee>

                  <Employee>

                    <FirstName>FirstName_1</FirstName> 

                    <LastName>LastName_1</LastName> 

                    <RecordID>RecordID_1</RecordID> 

                    <UserID>UserID_1</UserID> 

                    <Address>Address_1</Address> 

                    </Employee>

                  <Employee>

                    <FirstName>FirstName_0</FirstName> 

                    <LastName>LastName_0</LastName> 

                    <RecordID>RecordID_0</RecordID> 

                    <UserID>UserID_0</UserID> 

                    <Address>Address_0</Address> 

                    </Employee>

                  <Employee>

                    <FirstName>FirstName_2</FirstName> 

                    <LastName>LastName_2</LastName> 

                    <RecordID>RecordID_2</RecordID> 

                    <UserID>UserID_2</UserID> 

                    <Address>Address_2</Address> 

                    </Employee>

                  <Employee>

                    <FirstName>FirstName_1</FirstName> 

                    <LastName>LastName_1</LastName> 

                    <RecordID>RecordID_1</RecordID> 

                    <UserID>UserID_1</UserID> 

                    <Address>Address_1</Address> 

                    </Employee>

                    </ns0:Employees>

                  ——————————————–

                  Here is the XSLT:

                  ——————————————-

                  <xsl:stylesheet xmlns:ns0=”http://BizTalk_Server_Project1.Employees&#8221; xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221; xmlns:msxsl=”urn:schemas-microsoft-com:xslt” xmlns:var=”http://schemas.microsoft.com/BizTalk/2003/var&#8221; exclude-result-prefixes=”msxsl var” version=”1.0″>

                  <xsl:output omit-xml-declaration=”yes” method=”xml” version=”1.0″ />

                  <xsl:key name=”duplicateKey” match=”Employee/UserID” use=”.” />

                  <xsl:template match=”/”>

                  <xsl:apply-templates select=”/ns0:Employees” />

                  </xsl:template>

                  <xsl:template match=”/ns0:Employees”>

                  <xsl:variable name=”Employees”>

                  <xsl:for-each select=”Employee/UserID”>

                  <xsl:variable name=”group” select=”key(‘duplicateKey’,.)” />

                  <xsl:if test=”generate-id($group[1]) = generate-id()”>

                  <xsl:if test=”count($group) &lt; 2 or count($group) &gt; 1″>

                  <xsl:element name=”Employee”>

                  <xsl:element name=”UserID”>

                  <xsl:value-of select=”$group[1]” />

                  </xsl:element>

                  <xsl:element name=”FirstName”>

                  <xsl:value-of select=”/ns0:Employees/Employee[UserID=$group[1]]/FirstName” />

                  </xsl:element>

                  <xsl:element name=”LastName”>

                  <xsl:value-of select=”/ns0:Employees/Employee[UserID=$group[1]]/LastName” />

                  </xsl:element>

                  <xsl:element name=”RecordID”>

                  <xsl:value-of select=”/ns0:Employees/Employee[UserID=$group[1]]/RecordID” />

                  </xsl:element>

                  <xsl:element name=”Address”>

                  <xsl:value-of select=”/ns0:Employees/Employee[UserID=$group[1]]/Address” />

                  </xsl:element>

                  </xsl:element>

                  </xsl:if>

                  </xsl:if>

                  </xsl:for-each>

                  </xsl:variable>

                  <xsl:choose>

                  <xsl:when test=”count(msxsl:node-set($Employees)/Employee/UserID) &gt; 0″>

                  <xsl:element name=”Employees” namespace=”http://BizTalk_Server_Project1.Employees”&gt;

                  <xsl:copy-of select=”$Employees” />

                  </xsl:element>

                  </xsl:when>

                  <xsl:otherwise>

                  <xsl:copy-of select=”.” />

                  </xsl:otherwise>

                  </xsl:choose>

                  </xsl:template>

                  </xsl:stylesheet>

                   

                  ——————-

                  output:

                  ——————–

                  <?xml version=”1.0″ encoding=”utf-8″?>

                  <Employees xmlns=”http://BizTalk_Server_Project1.Employees”&gt;

                  <Employee xmlns=””>

                  <UserID>UserID_0</UserID>

                  <FirstName>FirstName_0</FirstName>

                  <LastName>LastName_0</LastName>

                  <RecordID>RecordID_0</RecordID>

                  <Address>Address_0</Address>

                  </Employee>

                  <Employee xmlns=””>

                  <UserID>UserID_1</UserID>

                  <FirstName>FirstName_1</FirstName>

                  <LastName>LastName_1</LastName>

                  <RecordID>RecordID_1</RecordID>

                  <Address>Address_1</Address>

                  </Employee>

                  <Employee xmlns=””>

                  <UserID>UserID_2</UserID>

                  <FirstName>FirstName_2</FirstName>

                  <LastName>LastName_2</LastName>

                  <RecordID>RecordID_2</RecordID>

                  <Address>Address_2</Address>

                  </Employee>

                  </Employees>

          • #23088

            Can you please send me sample project for that. it’s relay help for me.

            Thanks,

            Oyash

            [email protected]

    • #22535

      Hi,

      Directly mapping 2 source schema to 1 destination schema is not possible directly. You first create an orchestration and drop the transformation shape. Specify two input schemas and one output schema by selecting new map in drop down. By selecting ok a map will be created with two source and one destination schema.

      Hope this will answer your query.

      Regards,

      Sanjay Ahuja

       

      • #22537

        Thanks Sanjay! I already tried that. Only issue I had was linking records between both source schemas by their primary key IDs. ID gets correctly populated from first source as many records are in first source but for phone numbers, only first record gets populated in destination for all the records.

Viewing 2 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.