Home Page › Forums › BizTalk 2004 – BizTalk 2010 › multiple source mapping issue › Re: multiple source mapping issue
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″ xmlns=”http://BizTalk_Server_Project1.CustomerName” targetNamespace=”http://BizTalk_Server_Project1.CustomerName” xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
<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″ xmlns=”http://BizTalk_Server_Project1.CustomerPhone” targetNamespace=”http://BizTalk_Server_Project1.CustomerPhone” xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
<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″ xmlns=”http://BizTalk_Server_Project1.CustomerRecord” targetNamespace=”http://BizTalk_Server_Project1.CustomerRecord” xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
<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”>
<InputMessagePart_0>
<ns1:Customers xmlns:ns1=”http://BizTalk_Server_Project1.CustomerName”>
<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”>
<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” xmlns:msxsl=”urn:schemas-microsoft-com:xslt” xmlns:var=”http://schemas.microsoft.com/BizTalk/2003/var” exclude-result-prefixes=”msxsl var s2 s0 s1 userCSharp” version=”1.0″ xmlns:s2=”http://schemas.microsoft.com/BizTalk/2003/aggschema” xmlns:ns0=”http://BizTalk_Server_Project1.CustomerRecord” xmlns:s0=”http://BizTalk_Server_Project1.CustomerPhone” xmlns:s1=”http://BizTalk_Server_Project1.CustomerName” xmlns:userCSharp=”http://schemas.microsoft.com/BizTalk/2003/userCSharp”>
<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 <= $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 <= $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 <= $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 <= $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
