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;

 callmap1

 

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=\”http://www.w3.org/1999/XSL/Transform\” 

xmlns:msxsl=\”urn:schemas-microsoft-com:xslt\”

xmlns:var=\”http://schemas.microsoft.com/BizTalk/2003/var\” 

xmlns:SystemWebHttpUtility=\”http://schemas.microsoft.com/BizTalk/2003/System.Web\”

xmlns:s0=\”http://HtmlForm\”

xmlns:ns0=\”http://Oracle.XmlGateway.Form\”

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:element>

</xsl:template>

<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))\”/>

</xsl:element>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

 

 

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;

 

<ExtensionObjects>
<ExtensionObject
Namespace=”http://schemas.microsoft.com/BizTalk/2003/System.Web”
AssemblyName=”System.Web, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a” ClassName=”System.Web.HttpUtility” />
</ExtensionObjects>

 

 

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

turbo360

Back to Top