A while back I wrote about calling external assemblies from within a BizTalk map. A problem I mentioned was that the member variable in the class that the map was calling seemed to be getting shared amongst execution instances. Each map creates a sequential page number in the XSLT and puts it into the destination XML. However, I’d see output where the first message had pages “1..3..5..7..8” and the second message had pages “2..4..6..9.” Very strange. I thought I fixed the problem, but it surfaced today in our Test environment.
So, I set out to keep everything local to the map and get rid of external assembly calls. After banging my head for a few minutes, I came up the perfect solution. I decided to mix inline script with inline XSLT. “Madness” you say? I built a small test scenario. The map I constructed looks like this:
In the first Scripting functoid, I have “inline C#” selected, and I created a global variable. I then have a function to increment that variable and return the next number in sequence.
Did you know that you could have “global variables” in a map? Neat stuff. If I check out the XSLT that BizTalk generates for my map, I can see my function exposed as such:
Now I know how to call this within my XSLT! The second Scripting functoid’s inline XSLT looks like this:
Notice that I can call the C# method written in the previous functoid with this code:
The “prefix” is the auto-generated one from the XSLT. Now, all the calculations are happening locally within the map, and not relying on outside components. The result of this map is a document that looks like this:
There you go. Using global variables within a BizTalk map and calling a C# function from within the XSLT itself.
Technorati Tags: BizTalk
This is a wonderful diamond in the rough for BizTalk maps. One thing to mention is that you can call your map global variable from an Inline C# script functoid as well. Using your example above, instead of using an xslt Call Template, use the Inline C# option and enter “return GetPageNumber();” in the inline script buffer section and it will return your page number as well. Either way, thanks for the blog post, it was very helpful.
hi, your article is very helpful. I would like to know how the call would change if I had to pass a parameter to the GetPageNumber function. In my case I have a XSLTvariable that needs to be passed as a parameter to a C# function. Your help is highly appreciated. Thanks,asrinivasan.
Well, that variable itself would have to be able to change, right? And XSL variables cannot, I thought.
Amazing stuff, Helped me a lot.
Thank you so much !
Hi, thanks for your post. Can you attach the code file here?I tried using your sample but getting error in xslt template. Anyway I got the work around using script, iteration and index functoids using global variables.
Hi Venu, don’t think I have the code around anymore. However, I think the screenshots show the whole thing!
How will it be calling a C# function but it is not an inline one?
I’m trying to call an inline c# function from the inline xslt and I am able to call one that has no parameters fine but this other function takes two input parameters, any sample on how to build this in xslt I tried a ton of ways and all fail. Regards
This appears to do what you need … http://nathanfernandez.me/2012/03/20/how-to-write-inline-c-within-biztalk-xslt-custom-map/
Terrific …. Thanks for taking the time …