This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Indexing in XSLT
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sun, 11 Aug 2002 12:06:24 -0700 (PDT)
- Subject: [xsl] Re: Indexing in XSLT
- Reply-to: xsl-list at lists dot mulberrytech dot com
--- Maulik Modi <MModi at qcorps dot com> wrote:
> I need some help to solve this problem. Any help is appreciated.
>
> I have an instance document that gives me a list of available dates
> to
> choose from. I get passed another date which I have to compare
> against
> this
> list and return the matched date.
>
> If no match is found in the list, and the date passed is lower, I
> need
> to
> return the next higher date from the list. For example, if the date
> passed
> is Aug 10, 2002 and it is not in the available list, I need to return
> the
> next available date which could be Aug 12, 2002. Also I need to check
> for
> month end and year end. So if Aug 30 is passed, I will need to pass
> back Sep
> 2 (if available in the list).
>
> The last requirement is if no match is found, and the date passed is
> higher,
> I need to pass a null. For example, the date passed is Sep 30 and the
> last
> date in the list is Aug 15, I need to pass back a null (or empty
> string).
>
> I have used keys and the sample code I am pasting here is in working
> mode
> and does not include everything I have tried. Any help is
> appreciated.
>
> Instance XML:
> <acquisitions>
> <delivery zip="06850">
> <date>07/31/2002</date>
> <date>08/01/2002</date>
> <date>08/02/2002</date>
> <date>08/05/2002</date>
> <date>08/31/2002</date>
> <date>09/01/2002</date>
> </delivery>
> </acquisitions>
>
[code snipped]
You need first to convert your dates in a better format, e.g.
yyyy/mm/dd
In this format two dates can be compared simply like this:
translate($date1, '/', '') > translate($date2, '/', '')
The XSelerator XSLT editor and debugger comes with very nice
datetime.xsl library. For example how to use this library see my
calendar application at:
http://www.topxml.com/code/default.asp?p=3&id=v20020711152545&ms=20&l=&sw=All
In case the dates are sorted, you can perform binary search to find
your date -- for examples look at:
http://www.topxml.com/code/default.asp?p=3&id=v20010309084536
or
http://www.topxml.com/code/default.asp?p=3&id=v20011001235959
=====
Cheers,
Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list