xsl-list
[Top] [All Lists]

RE: [xsl] Comparing Integers

2007-10-17 10:03:53
Are you doing this in XSLT 1.0 or 2.0? 

In 2.0 you can compare these values directly by casting them to xs:dateTime
and then subtracting to get the difference as an xs:dayTimeDuration.

In 1.0 you may be able to take advantage of the library routines at
www.exslt.org.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Aaron Johnson [mailto:artpunx(_at_)gmail(_dot_)com] 
Sent: 17 October 2007 17:55
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Comparing Integers

Hello...

I have set up some tests to compare Integers, but wish to 
refine the comparison. I have some xml:

<submissionDeadline>2027-10-04T09:00:00.0000000-00:00</submiss
ionDeadline>
<submissionDeadline>2007-10-03T09:00:00.0000000-00:00</submiss
ionDeadline>
<submissionDeadline>2007-10-01T08:00:00.0000000+01:00</submiss
ionDeadline>
<submissionDeadline>2007-09-10T12:00:00.0000000+01:00</submiss
ionDeadline>


This is selected and concatenated into an integer:

<xsl:variable name="submissionDeadlineString"
select="concat(substring(submissionDeadline, 1,4)... etc etc

I then concatenate the current time / date etc:

<xsl:variable 
name="currentTime">2007-10-04T09:00:00.0000000+01:00</xsl:variable>
<xsl:variable name="currentTimeString"
select="concat(substring($currentTime, 1,4)....etc etc

...then test against each other:

<xsl:when test="$currentTimeString &lt; = 
$submissionDeadlineString"><xsl:call-template
name="ontime"/></xsl:when>

I would like to be able to test for 4 different outcomes, 
ontime, within24Hours, within10Days and past10Days. I have 
set up variable and tests thus far:

<xsl:variable 
name="currentTime">2007-10-04T09:00:00.0000000+01:00</xsl:variable>
<xsl:variable name="currentTimeString"
select="concat(substring($currentTime, 1,4)....etc etc 
<xsl:variable name="within24Hours"
select="number($submissionDeadlineString + 1000000)"/> 
<xsl:variable name="within10Days"
select="number($submissionDeadlineString + 1000001)"/> 
<xsl:variable name="past10Days"
select="number($submissionDeadlineString + 10000001)"/>

<xsl:choose>
<xsl:when test="$currentTimeString &lt; = 
$submissionDeadlineString"><xsl:call-template
name="ontime"/></xsl:when>
<xsl:when test="$currentTimeString &lt; = 
$within24Hours"><xsl:call-template
name="twentyFourHourRule"/></xsl:when>
<xsl:when test="$currentTimeString &lt; = 
$within10Days"><xsl:call-template 
name="tenDayRule"/></xsl:when> <xsl:when 
test="$currentTimeString &gt; = 
$past10Days"><xsl:call-template 
name="plusTenDay"/></xsl:when> </xsl:choose>

...so far, only the "ontime" and "plusTenDay" tests work.

Am I headed in the right direction? Can anyone offer any 
advice please?

Thank you.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>