Connected Pawns

October 8, 2008

Call a .Net assembly from custom XSLT

Filed under: BizTalk — Tags: , — mbrimble @ 12:24 am

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


1 Comment »

  1. [...] two solutions from posts by Greg Forsyth namely http://www.biztalkgurus.com/forums/t/12350.aspx and http://connectedpawns.wordpress.com/2008/10/08/call-a-net-assembly-from-custom-xslt/ ( I had to use my blog because the original link seems to be broken). I have decided to record how [...]

    Pingback by How to copy the entire node to element of string type in a map « Connected Pawns — August 1, 2009 @ 10:17 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.