Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Comparison problem.

Status
Not open for further replies.

rkckjk

IS-IT--Management
Apr 27, 2001
34
US
Here is my XML file:
<?xml version="1.0" standalone="yes"?>
<MSR>
<Info>
<TODAY>Saturday, January 29, 2005</TODAY>
<SSEC>4:00 pm</SSEC>
</Info>
</MSR>

My XSL file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="version="1.0">
<xsl:eek:utput method="html" indent="yes" />

<xsl:template match="/">
<html>
<head>

<style type="text/css">
body {background-color:#f5f5f5}
h1 {text-align:center}
h4 {color:Blue;font-size:small;text-align:center}
li {font-weight:bold}
</style>

</head>
<body>

<H1>Status Report</H1>

<xsl:apply-templates select="MSR/Info"/>

</body>
</html>

</xsl:template>

<xsl:template match="Info">

<xsl:choose>
<xsl:when test="(string-length(SSEC)">
<H4><xsl:apply-templates select="TODAY"/></H4>
</xsl:when>
<xsl:eek:therwise>
<H4><xsl:apply-templates select="TODAY"/></H4>
<H4><xsl:text>No Current Updates</xsl:text></H4>
</xsl:eek:therwise>
</xsl:choose>

<xsl:if test="(SSEC !='')">
<h3>Securities</h3>
<xsl:apply-templates select="SSEC"/>
</xsl:if>


</xsl:template>

<xsl:template match="TODAY[. != '']">
<h4>Cycle Run Of: <font color="#00008B"><xsl:value-of select="."/></font></h4>
</xsl:template>

<xsl:template match="SSEC[. != '']">
<li>Securities System Extract Cycle ended at: <font><xsl:attribute name="color">
<xsl:variable name="hours" select="number(substring-before(.,':'))"/>
<xsl:variable name="minutes" select="number(substring(substring-after(.,':'),1,2))"/>
<xsl:variable name="AM" select="contains(.,'AM')"/>
<xsl:variable name="AM1" select="contains(.,'am')"/>
<xsl:choose>
<xsl:when test="((($AM or $AM1) and ($hours = 12) and ($minutes &gt;= 0)) or (($AM or $AM1) and ($hours &gt;= 2) and ($minutes &gt; 30)) or (($AM or $AM1) and ($hours &gt; 2) and ($minutes &gt;= 0)))">#800000
</xsl:when>
<xsl:eek:therwise>#00008B
</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute><xsl:value-of select="." /></font></li>
</xsl:template>
<xsl:template match="*"/>

</xsl:stylesheet>

Cuurrently the XML file node 'TODAY' has the date of: <TODAY>Saturday, January 29, 2005</TODAY>

I found this XSL script that gets the system date but I'm not sure how to incorporate it in my XSL file above and compare the dates in the XSL file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="version="1.0">
<xsl:script>
<![CDATA[
function retDate( )
{
var now = new Date();
return now;
}
]]>
</xsl:script>
<xsl:eval>retDate() </xsl:eval>
</xsl:stylesheet>

Here's what I need to do --- if the system date is greater than the 'TODAY' date by 2 days example: '<TODAY>Saturday, January 29, 2005</TODAY>

System date: Monday, January 30, 2005

Then I would want to use the following template for 'SSEC': then the one above which parses out the time and changes the font color depending what time it is.

<xsl:template match="SSEC[. != '']">
<li>Securities System Extract Cycle ended at: <font color="black"><xsl:value-of select="." /></font></li>
</xsl:template>

I hope my explanation of the problem is good enough.

Thanks
 
Saturday, January 29, 2005
is not a comparable date format.

The W3C XML spec says you should use ISO-8601 format:
[tab][tab]2005-01-29T00:00:00

If you need a display value, then use two fields, one to compare with, and one to show the user.

I'm not sure that retDate script will work. You might need to pass in the current date/time as an XSL parameter.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top