Call a .Net assembly from custom XSLT

Posted: October 8, 2008  |  Categories: BizTalk Uncategorized

I discovered this while trying to re-engineer some BizTalk assemblies that I did not have the source code. On unraveling a map using reflector I found some custom XSLT in a map that we did not understand at first. I have decided to blog on this here because I thought that the concept of calling a .net assembly from XSLT is quite powerful.


The map we were trying to dissect was;



On examining the assembly further we discovered that the only functoid in the map was a scripting functoid that used the following custom XSLT;


<?xml version=\”1.0\” encoding=\”UTF-16\”?>

<!–Author: Greg Forsythe–>

<xsl:stylesheet xmlns:xsl=\”\” 






exclude-result-prefixes=\”msxsl var s0 SystemWebHttpUtility\” 

version=\”1.0\” >

<xsl:output omit-xml-declaration=\”yes\” version=\”1.0\” method=\”xml\” /> \n\t<xsl:template match=\”/\”>

<xsl:element name=\”ns0:XmlGatewayForm\”>

<xsl:call-template name=\”htmlFormData\”/>



<xsl:template name=\”htmlFormData\”>

<xsl:for-each select=\”//field[name != ‘Submit’]\”>

<xsl:variable name=\”var:v1\” select=\”name\” /> 

<xsl:element name=\”{$var:v1}\”>

<xsl:value-of select=\”SystemWebHttpUtility:UrlDecode(string(value))\”/>







The interesting bit is highlighted in red. This is calling the System.Web.HttpUtility.UrlDecode method from the .Net Framework using a custom XML extension which was defined as follows;


AssemblyName=”System.Web, Version=, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a” ClassName=”System.Web.HttpUtility” />



Now all is clear the map is taking the each name -value pair, matching on the name value, decoding  the value field and then finally copying the decoded value. As an aside I will post a custom pipeline component that does the same thing here in another post.


It was quite satisfying to google posts by Greg Forysthe using the above code as an example. If you want to look this up here it is; Pre-Processing on Send Port, in BizTalk and BizTalk Gurus – Reply to an Existing Message – Message Routing Woes


Back to Top