|
next
|
Subject: Re: xsl date time adding... Author: (Deleted User) Date: 13 Oct 2008 11:03 PM
|
oh i see, I'm still a newbie at this. But i got the same problem before
when I was tasked to convert the current time to the time based on GMT, so
with that , i had to add 8 hours each time i pull and transform the xml
date node required to be converted.
Take note that in xslt version 2, we can already use functions for
datetime manipulations etc , also, we can already use some datetime
functions like dateadd etc..
But in xslt version 1, we are ony limited in using templates, this was my
problem before becuase i was only limited to code using xslt version 1.
What i did was , I created my own set of templates that will be called
while I transform the date node. These templates will :
1. Select the current datetime node and converts it to a date-time format
that can be easily divided into :
a. Date, Time and Year
2. Get the time,day,month and year
(DoAddHour,DoAddDate,DoAddMonth,DoAddYear)
3. Pass the formatted current date as a variable to the DoAddTime, this
template should basically :
a.get the time in HH:mm:ss tt,
b. add 8 hours as per GMT requirement
c. Compare the resulting Time if this excedds 24 hours
d. if exceeds to 24 hours, call template DoAddDate
* .... do this until the DoAddYear template .... see the sample
templates below*
.. You can use a set of ms:format-date, ms:format-time, substring
-available functions in xslt version 1
the DoAddHour,DoaddDate, DoAddMonth, DoaddYear will depend on how it will be
used, as for me since I was tasked to display the output as, Monday, Feb
28, 2008, the template for DoAddHour,DoAddDate,DoAddMonth simply contained
a set of xsl:choose, xsl:when for days :Monday, Tuesday wednesday etc.. and
months: Jan, February, March , April.
ex..
* ** <xsl:template name="DoAddHour">
<xsl:param name='Hour'/>
<xsl:value-of select="$Hour +8"/>
</xsl:template>
<xsl:template name="DoAddDate">
<xsl:param name="Date"/>
<xsl:value-of select="$Date +1"/>
</xsl:template>
<xsl:template name="DoAddYear">
<xsl:param name="Year"/>
<xsl:value-of select="$Year+ 1"/>
</xsl:template>*
*<xsl:template name="DoAddOneDay">
<xsl:param name="DoDay"/>
<xsl:variable name="DayInAWeek" select="$DoDay"/>
<xsl:choose>
<xsl:when test="$DayInAWeek = 'Sun'">Mon</xsl:when>
<xsl:when test="$DayInAWeek = 'Mon'">Tue</xsl:when>
<xsl:when test="$DayInAWeek = 'Tue'">Wed</xsl:when>
<xsl:when test="$DayInAWeek = 'Wed'">Thu</xsl:when>
<xsl:when test="$DayInAWeek = 'Thu'">Fri</xsl:when>
<xsl:when test="$DayInAWeek = 'Fri'">Sat</xsl:when>
<xsl:when test="$DayInAWeek = 'Sat'">Sun</xsl:when>
</xsl:choose>
</xsl:template>*
* <xsl:template name="DoAddOneMonth">
<xsl:param name="DoMonth"/>
<xsl:variable name="MonthInAYear" select="$DoMonth"/>
<xsl:choose>
<xsl:when test="$MonthInAYear = 'Jan'">Feb</xsl:when>
<xsl:when test="$MonthInAYear = 'Feb'">Mar</xsl:when>
<xsl:when test="$MonthInAYear = 'Mar'">Apr</xsl:when>
<xsl:when test="$MonthInAYear = 'Apr'">May</xsl:when>
<xsl:when test="$MonthInAYear = 'May'">Jun</xsl:when>
<xsl:when test="$MonthInAYear = 'Jun'">Jul</xsl:when>
<xsl:when test="$MonthInAYear = 'Jul'">Aug</xsl:when>
<xsl:when test="$MonthInAYear = 'Aug'">Sep</xsl:when>
<xsl:when test="$MonthInAYear = 'Sep'">Oct</xsl:when>
<xsl:when test="$MonthInAYear = 'Oct'">Nov</xsl:when>
<xsl:when test="$MonthInAYear = 'Nov'">Dec</xsl:when>
<xsl:when test="$MonthInAYear = 'Dec'">Jan</xsl:when>
</xsl:choose>
</xsl:template>*
*This was not the best solution for my problem , but i had to resort to a
workaround because of the limitation of the system i was trying to add
content to. :0*
*I know this was a bit different bbut i hope i help you with an idea,..
keep me posted. ^_^*
On 10/13/08, stylus-studio-xslt Listmanager <
stylus-studio-xslt.listmanager@stylusstudio.com> wrote:
>
> From: tyler horath
>
> anyway that will work is fine by me. I just want the date to start at the
> current time on the first node, then to keep adding an hour to each node.
>
> <example>
> <item>
> <pubdate>10-13-2008 8:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 9:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 10:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 11:00</pubdate>
> </item>
> <item>
> <pubdate>10-13-2008 12:00</pubdate>
> </item>
> <item>
> <pubdate>10-14-2008 1:00</pubdate>
> </item>
> </example>
>
> and so on...
>
> And in doing this hopefully the days will change as the hours pass 24 or
> whatever.
>
>
> --
> To reply:stylus-studio-xslt.25319@stylusstudio.com
> To start a new topic:stylus-studio-xslt@stylusstudio.com
> To login:http://www.stylusstudio.com/SSDN/
> To (un)subscribe:stylus-studio-xslt.list-request@stylusstudio.com
>
--
"We can observe and theorize. But we can never know how. Reality is
something we can only approach"-albert enstein's pen
|
|
|
|