Re: [xsl] Release Date vs. Highlight Until Date

Subject: Re: [xsl] Release Date vs. Highlight Until Date
From: John <john-xsl-list@xxxxxxxx>
Date: Wed, 29 Sep 2004 08:33:11 -0700
Thanks to everyone who responded on this thread. I did have some time to read parts of an old copy of White's "Mastering XSLT" (not the best intro I think) over the weekend, and ordered another recommendation. I still don't understand why/when to use for-each and when to use apply-templates, but I seem to prefer for-each. I have restructured the XML and implemented a variety of the suggested techniques. One thing I'm still strugling with is how to select the date value for sorting. Say I have XML something like the following:

<items>
 <item release="20031212T121212" highlight="20041212T121212" />
</item>

where there could be any number of item elements. I want to select for sort one of the attributes from each item and use that in the sort. The attribute I want is release unless highlight is less than sysdate. Right now I am getting sysdate and doing the logic with extensions, but I would prefer to avoid this (I know I can get rid of the sysdate extension with parameters but I am more concerned about the comparison extension). My C# extension looks like this (I can't even be sure this is the right logic - it *seems* to work - but hopefully you get the idea). Thanks in advance to anyone who can convert this to pure XSL.

public string SortNewsDate( string strSysDate, string strHighlightUntilDate, string strReleaseDate )
{
DateTime dtResult = DateTime.MinValue;


try
{
if ( strSysDate != null && ! strSysDate.Equals( "" ))
{
if ( strHighlightUntilDate != null && ! strHighlightUntilDate.Equals( "" ))
{
dtResult = DateTime.ParseExact( strHighlightUntilDate, SC_DATE_FORMAT, null );
}


if ( dtResult.CompareTo( DateTime.ParseExact( strSysDate, SC_DATE_FORMAT, null )) < 0
&& strReleaseDate != null && ! strReleaseDate.Equals( "" ))
{
dtResult = DateTime.ParseExact( strReleaseDate, SC_DATE_FORMAT, null );
}
}
}
catch( Exception ex )
{
throw new Exception( ex.Message + strSysDate + " : " + strHighlightUntilDate + " : " + strReleaseDate );
}


           return( dtResult.ToString( SC_DATE_FORMAT ));
       }

Current Thread