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 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…)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s