XSLT map changes to not appear when re-deploying BizTalk Projects

I received the following e-mail from Joe, regarding a bug I found in BizTalk 2004 when developing maps with XSLT:

Hi! I was reading the post on ureader.com regarding a problem of not having XSLT changes show up when deploying a BT04 project when I saw your response (#2 of your listed solutions) about creating ‘a link from the root note of the source map to the root note of the destination map and delete the link to refresh the map.’ I was wondering if I could get a little clarification on exactly how you created the link. Any thoughts would be greatly appreciated! Thanks! -Joe

The bug Joe is talking about here relates to changes to an XSLT file (with the BizTalk map using that file in the ‘Custom XSL Path’), which do not appear when you re-deploy a project.

As an example, say you have developed a solution using custom XSLT files for your BizTalk map. You test the map in VS and everything works ok, so you go ahead and deploy the project and again, everything works as expected in the runtime environment (say the map is on a Receive Port). However, you notice that the output from the map needs a minor amendment, so you go back into your XSLT, correct the problem and test the map again from within VS – everything works fine. You re-deploy the project and test in the runtime environment and bam, the map hasn’t changed – the changes that were made to the XSLT didn’t get picked up. Huh?

I originally noticed this bug in BizTalk 2004, but have just tested against 2006 (not R2) and can confirm that it is also present in this version. I believe that the bug (?) is due to the fact that the artifact that is compiled (i.e. the map) hasn’t changed, so Visual Studio doesn’t know that the project needs to be re-compiled (the output windows tells me that ‘the project is up-to date’, even though I know I’ve changed the XSLT and it therefore isn’t).

As a work around, I suggest that you open the BizTalk map (not the XSLT) and trick VS into thinking that the map has changed – i.e. create a single link from the source to the destination document (it doesn’t matter which element) and then delete the link. VS will pickup the change and force the project (and your XSLT changes) to be re-compiled.

Happy XSLT-ing!

Inline C#, Javascript and JScript in XSLT

(Final) Update: I’ve uploaded a sample project to demonstrate using the StripWhitespace method in an XSL transformation. The project is provided as a zip file and contains a sample input message – download the sample project here.

Update: The stylesheet I’m using on modhul.com appears to be shrinking the images in this post on Firefox (IE appears to be unaffected) – simply right-click the image to view the correct size.

I’ve used inline Javascript in XSLT for BizTalk maps in the past, but came across the article Extending XSLT with JScript, C#, and Visual Basic .NET by Aaron Skonnard on MSDN last night that discusses, among other things, embedding C#!

Its faily simple to use – the following inline C# method strips whitespace from the input:

XSLT C# Snippet

Before the inline code will work, you’ll need to inform the XSLT processor about the msxsl and user prefix (user can be anything you want):

XSLT C# XML Namespace Declaration

Finally, you’ll need to call the inline method from the actual XSLT template:

XSLT C# Value-of

$InputField here is just an example, you can use any valid input to the value-of element.

This has been tested in BizTalk 2006 but not yet in 2004 (although I have Javascript working in 2004 so I can’t see any reason why it wouldn’t…)

Using custom xslt in the BizTalk mapper & nxslt2

We use custom XSLT in all of our BizTalk maps (simply because we couldn’t get the BizTalk mapper to provide us with the functionality we needed when we first started using the product!) We now have approx. 70 XSLT maps in production use and I plan on blogging about their use in the near future.

In the meantime, I want to tell you about a great XSLT tool I discovered today. I completed development of some .Net 2.0 code earlier and needed a quick way of developing some maps – rather than developing a quick and dirty WinForms app I downloaded the great nxslt2 tool from xmllabs.net xmllab.net

Released under the BSD Licence, nxslt2 is a .NET 2.0 Framework application, written in C# 2.0 and is fantastic for RAD XSLT development. Using it is as simple as:

nxslt2 sourcefile.xml transformation.xslt > output.xml

nxslt2 can be downloaded from here (in either source or binary form); documentation is provided here. Enjoy!