Blogging BizTalk

Lets Discuss BizTalk

Find the maximum / minimum date in BizTalk maps using XSLT or with Cumulative Functoids


Challenge: BT maps xslt are essentially 1.0 indicating every data you see in there will be treated as string by default hence the sort function will not work for date time data type, please note xslt 2.0 does have the ability to recognize native data type.

Solution: First thing you need to do is string operate on the date time data to extract only the numbers, for example 2013-07-24T03:38:34.844467 shall be converted to 20130724033834 decimal which makes it fit to be sorted.

So my map will look like this.

Image

Content of the scripting functioud:
public decimal ChangeDateToInt(string param1)
{
      return Convert.ToDecimal(((param1.Replace(“-“, “”)).Replace(“T”, “”)).Replace(“:”, “”));
}

In case you don’t want to use the cumulative max functoid please resort to following XSLT scrip to accomplish this, please note you will still need to do the string operation to extract the numeric equivalent value of the date time.:

        <!–Calculate Max Date Start–>
        <xsl:variable name=”MaxDate”>
         <xsl:for-each select=”YOUR XPATH TO THE DATE NODE COLLECTION”>
          <xsl:sort select=”.” data-type=”number” order=”descending”/>
          <xsl:choose>
           <xsl:when test=”position() = 1″>
            <xsl:value-of select=”.”/>
           xsl:when>
          xsl:choose>
         xsl:for-each>
        xsl:variable>
        <!–Calculate Max Date End–>
        <ns0:YourMaxDateNodeInSchema>
         <xsl:value-of select=”$MaxDate”/>
        ns0:YourMaxDateNodeInSchema>

Please leave me a comment in case you have any questions.

Advertisements

2 responses to “Find the maximum / minimum date in BizTalk maps using XSLT or with Cumulative Functoids

  1. Nazeer June 29, 2014 at 5:19 pm

    If I go with cumulative functoid using C# to replace date format to decimal, I need to recreate date format at target mapping also right? and for that again need to use C# function. But does the same required for XSLT as well?

  2. Pushpendra Singh June 29, 2014 at 9:08 pm

    Thanks for you comment. Your assumption is correct Nazeer you need to convert it back to date time at destination.xslt 1.0 doesn’t supports date time sorting, so even if you just using xslt, you will still need to convert date to int before use xslt sort function.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

D Goins Insperience

Technological outformation for this day and age

[INACTIVE BLOG] Connected Thoughts - Thiago Almeida

Connected systems and the occasional picture

Uri Katsir's Blog

BizTalk , BizTalk RFID and .NET

prashantbiztalkblogs

My BizTalk Experiences

BizTalk Server Tutorial

BizTalk Server Concepts and Common Errors

Extremely Talented Monkeys

A Technical Blog by Ed Jones: Azure, .NET, BizTalk, WCF, and SQL Server

On All Things Web

Discussing web development without limits

Vikas Bhardwaj's Blog

Articles about BizTalk Server and .NET C#

Cloud develop

a blog about (cloud) development... because I'm a nerd

Hooking Stuffs Together

My learning logs from day to day work experience about Integration platform using Microsoft technologies.

Connected Pawns

Mainly BizTalk & Little Chess

jhelatissimo

a blogger in the process.

MS Innovations Blog

Tips, Tricks, and Workarounds for BizTalk and other Microsoft technologies

srirambiztalks

Katradhu Kaialavu,Kalladhadhu Ulagalavu!

Vijay Microsoft Technical

BizTalk, WCF, ESB ToolKit, Windows Azure

Mind Over Messaging

Musings on BizTalk, Azure, and Enterprise Integration

%d bloggers like this: