Old BizTalk XSLT Tricks 1 – Array.Contains()

Posted: October 6, 2023  |  Categories: Azure BizTalk
Tags: arrays XSLT

This a story about writing XSLT for use in Azure Integration Account and the Array.Contains() method. In the first place I was using the BizTalk mapper to create the XSLT. I had not done this for a long while and had forgotten some of its limitations.

Initially using Array.Contains() to check if an array contains a specific element fails with this error.

'System.Array' does not contain a definition for 'Contains' and no extension method 'Contains' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

In .NET 3.5, you can use the Contains method of the System.Linq namespace. However, in .NET 2.0, this method is not available . Unfortunately, the BizTalk mapper is very old and does not support modern C#.

Nevertheless, I got over this limitation by casting the array to the appropriate IList interface.

///*Check if a CSV delimited string contains a specific element

public string ContainsItem(string itemExclusions, string item)
	string[] items = itemExclusions.Split(',');
	//return items.Contains(item);
	System.Collections.Generic.List<string> itemList = new System.Collections.Generic.List<string>(items);
	return itemList.Contains(item).ToString();

This scripting functoid code takes an input of a delimited comma separated variable string and a string value from the inbound XML. I want to check if that string is present in the CSV string. Note I return string instead of a bool type because I don’t trust BizTalk mapper to handle boolean types correctly.

In the .NET Framework version 2.0, the Array class implements the System.Collections.Generic.IListSystem.Collections.Generic.ICollection, and System.Collections.Generic.IEnumerable generic interfaces. The implementations are provided to arrays at run time, and therefore are not visible to the documentation build tools. As a result, the generic interfaces do not appear in the declaration syntax for the Array class, and there are no reference topics for interface members that are accessible only by casting an array to the generic interface type (explicit interface implementations).

Trick when using Array.Contains() – CodeProject


To conclude with, I show that using the BizTalk mapper Scripting functoids be careful to use C# that is compatible with .NET 2.0. I was using Visual Studio 2015 with BizTalk 2016.

In addition to this, if you validate a BizTalk map you can use the XSLT in a Logic App transformation shape. The scripting functoid shape appears in the CDATA section as msxml.

If you use the XSLT in an XML transformation shape in an Azure Consumption Logic App, do you have the same limitations? Do you get different behaviour if you use the new Visual code Data Mapper for Standard Logic Apps? The limitations for data mapping in Logic Apps do not give an answer either way.


Back to Top