I recently came across an interesting scenario that forced me to use pure XSLT instead of the BizTalk mapper to create a XSD transform. The interesting part was that since BizTalk 2010 only supports Xpath 1.0 functions I could not use any decent date or math style functions that are supported in Xpath 2.0. If I was using the visual mapper I could easily use a functoid or inline C#/XSLT etc. But, since I was using a completely 100% XSLT approach how could I implement more complex date or math calculations using just XSLT and Xpath 1.0.
A solution to this problem is to write inline C# manually within the XSLT. Here is what you need to do:
1) Add the following attributes into your opening xsl:stylesheet tag ….
exclude-result-prefixes=“msxsl var userCSharp ns0 data“
2) Add in the following msxml tag and nested CDATA section after the closing xsl:template tag but before the xsl:stylesheet closing tag. Then add in your C# into the CDATA section.
public int GetDayFromDateTime(string value)
DateTime dtvalue = DateTime.Parse(value);
4) Reference the C# function from within your XPath select value.
<xsl:variable name=“dayOfMonth” select=“userCSharp:GetDayFromDateTime($currentDT)“ />
Now this is nothing that new in terms of technology capability, but I wanted to highlight the problem area (complex date/math function in 100% XSLT BizTalk map) and that BizTalk still does not support Xpath 2.0. I believe Aaron Skonnard wrote an article on this technique back in 2002, however this technique is as valid today as it was then.
I just hope that the new EAI Integration capability coming to Azure soon has support for Xpath 2.0. I think it might be a little too soon to get support for Xpath 3.0 but Xpath 2.0 should be a minimum.