We can use inline XSLT in Biztalk maps for transformations. I'll be using inline XSLT and calling a simple C# class in the XSLT. For this we have to write XSLT in scripting functiod also write a class in inline c# of scripting functiod.
Below is the source schema used for map.
Destination Schema is :
Map goes like this :
XSLT goes like this :
<Output>
<xsl:for-each select = "Root">
<Desti>
<Name><xsl:value-of select = "Name/text()" />
</Name><ID><xsl:value-of select ="ID/text()"/>
</ID><xsl:variable name="var:v1" select="userCSharp:concatAddress(string(Name/text()) , string(Address/text()))" />
<Full_Address>
<xsl:value-of select ="$var:v1" />
</Full_Address>
<xsl:variable name="var:v2" select = "userCSharp:AddID (string (ID/text() ),string(Roll_No/text()))"/>
<Roll_No><xsl:value-of select = "$var:v2"/>
</Roll_No><xsl:if test="not(string(ID/text())=0)">
<Original_RollNo>
<xsl:value-of select ="ID/text()"/>
</Original_RollNo>
</xsl:if></Desti>
</xsl:for-each>
</Output>
Below is the source schema used for map.
Destination Schema is :
Map goes like this :
XSLT goes like this :
<Output>
<xsl:for-each select = "Root">
<Desti>
<Name><xsl:value-of select = "Name/text()" />
</Name><ID><xsl:value-of select ="ID/text()"/>
</ID><xsl:variable name="var:v1" select="userCSharp:concatAddress(string(Name/text()) , string(Address/text()))" />
<Full_Address>
<xsl:value-of select ="$var:v1" />
</Full_Address>
<xsl:variable name="var:v2" select = "userCSharp:AddID (string (ID/text() ),string(Roll_No/text()))"/>
<Roll_No><xsl:value-of select = "$var:v2"/>
</Roll_No><xsl:if test="not(string(ID/text())=0)">
<Original_RollNo>
<xsl:value-of select ="ID/text()"/>
</Original_RollNo>
</xsl:if></Desti>
</xsl:for-each>
</Output>
C# script goes like this :
public string concatAddress(string Name, string Address){
return Name + Address;}
public int AddID(int ID,int RollNo){
return ( ID + RollNo); }
In XSLT code I have called both these methods. Just droppping the inline C# functiod on mapper surface will work fine,also we don't have to connect this sfunctiod to any node in destination schema.
No comments:
Post a Comment