473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Using XSL to calculate time (t = hh:mi + mi)

Hi,
I have an XML source which gives me the start time (in the format
hh:mi) of a program and the duration of the program (in minutes).

With XSLT only, I would like to generate the time the next program
starts.
Ex: If the current program starts at 10:30 and lasts for 60 minutes, I
wish to display that the next program starts at 11:30.
The server seems to be running XSL 1.0.

I am quite new to XSLT, and have tried Googling this with no luck so
far.

Can anyone please help me with this? (Preferably with code example..
;-)

Regards, Per Magnus

Dec 1 '06 #1
5 3568
ke*********@hotmail.com wrote:
With XSLT only, I would like to generate the time the next program
starts.
Ex: If the current program starts at 10:30 and lasts for 60 minutes, I
wish to display that the next program starts at 11:30.
The server seems to be running XSL 1.0.
XSLT/XPath 1.0 have basic string parsing functions which allow you to
split up that value into two numbers, then you can compute the time in
minutes, add the other minutes value and then you need to convert back
to a time value.
XPath string functions are here:
<http://www.w3.org/TR/xpath#section-String-Functions>
XPath number operators (div, mod) and functions are here:
<http://www.w3.org/TR/xpath#numbers>
<http://www.w3.org/TR/xpath#section-Number-Functions>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 1 '06 #2

Martin Honnen schrieb:
ke*********@hotmail.com wrote:
XSLT/XPath 1.0 have basic string parsing functions which allow you to

that sounds not like a job xslt, because the string functions (i.e.
substring-after ect...) are TOO basic.

Other question: which XSLT-Parser ?

Dec 1 '06 #3
I'm not sure what XSLT parser we have here. Any easy way to figure this
out?
Its hard to find the administrator of the server here, and my guess is
that if I find him, he does not have this information at the top of his
head.

Is the XSLT parser significant for this type of task?

I have implemented a preliminary solution to this, though, using string
parsing anf number(), substing(), floor(), div and mod functions in the
XSL statement.

For special interested, the time for next program became:

<xsl:choose>
<xsl:when test =
"floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2)) &gt; 23" >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2)) mod 24"/>
</xsl:when>
<xsl:otherwise >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2))"/>
</xsl:otherwise>
</xsl:choose>:<xsl:choose><xsl:when test =
"((number(substring(nr/st,4,2))+number(nr/ln)) mod 60) &lt;
10">0<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsl:when>
<xsl:otherwise >
<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsl:otherwise>
</xsl:choose>

Thanks for help!

-Per Magnus

fedro wrote:
Martin Honnen schrieb:
ke*********@hotmail.com wrote:
XSLT/XPath 1.0 have basic string parsing functions which allow you to


that sounds not like a job xslt, because the string functions (i.e.
substring-after ect...) are TOO basic.

Other question: which XSLT-Parser ?
Dec 1 '06 #4
ke*********@hotmail.com schrieb:

<xsl:choose>
<xsl:when test =
"floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2)) &gt; 23" >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2)) mod 24"/>
</xsl:when>
<xsl:otherwise >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2))"/>
</xsl:otherwise>
</xsl:choose>:<xsl:choose><xsl:when test =
"((number(substring(nr/st,4,2))+number(nr/ln)) mod 60) &lt;
10">0<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsl:when>
<xsl:otherwise >
<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsl:otherwise>
</xsl:choose>

Thanks for help!

-Per Magnus
Look at this. That's my point, that is not a job for XSLT, maybe
XSLT2.0 or so, but that is cruel to debug and performance and
everything.

This job has to be done by an extension, i.e. a very shot Java Funtion.

Dec 1 '06 #5

<ke*********@hotmail.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
Hi,
I have an XML source which gives me the start time (in the format
hh:mi) of a program and the duration of the program (in minutes).

With XSLT only, I would like to generate the time the next program
starts.
Ex: If the current program starts at 10:30 and lasts for 60 minutes, I
wish to display that the next program starts at 11:30.
The server seems to be running XSL 1.0.

See my Calendar XSLT app:

http://www.topxml.com/code/?p=3&id=v...odelib&sw=lang

It uses a library datetime_lib.xsl (written entirely in XSLT by Martin
Rowlinson) from XSelerator and can be accessed from the trial download.

As for what can be done with XSLT and how efficient this is -- many people
have really wrong believes. Read my blog to find examples:

http://dnovatchev.spaces.live.com/Blog/

or see my snippets (written many years ago) on topxml.com:

http://www.topxml.com/members/profile.asp?id=i1005

Cheers,
Dimitre Novatchev
Dec 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

62
by: christopher diggins | last post by:
Since nobody responded to my earlier post , I thought I would try to explain what I am doing a bit differently. When multiply inheriting pure virtual (abstract) base classes, a class obviously...
6
by: Richard A. Lowe | last post by:
I'm using P/Invoke to call SendInput (using code culled from these newsgroups!) to send mouse events to a window. But I'm unsure how to send double-clicks. A VB6 article I saw on SendInput...
5
by: Totto | last post by:
Hi, Is it possible to convert date to dd mon yyyy hh:mi(24h) Thanks Totto
26
by: canteyn | last post by:
I am currently working on a lab for my computer science class, and we are to write program (using a function) to calculate the monthly payment. We also are reading the principal loan, interest rate,...
0
by: jobs | last post by:
re: Oracle Exceeded maximum idle time I have asp.net web gridview that is populated by a function that calls an Oracle procedure that returns a dataset. At most, it might take 2 or 4 seconds to...
1
by: RubyRed | last post by:
Using SQL Server 2000. Basically, I am trying to calculate each minute of an employee scheduled time during their work shift. In the table below shows only the times that the shift begin...
3
by: PeeS290 | last post by:
Hi all, Where can I find guidelines about programming SQL based applications in VC++ ? Since MS SQL Server 2008 is strongly promoted, I cannot understand why there is no help for developers....
6
by: gozdeata | last post by:
hey there, i m trying to get only time information of a date type variable. i got a column in type of char, it keeps time info in hh:mm format - 5 characters when i tried to convert it to date...
0
amitpatel66
by: amitpatel66 | last post by:
Hi All, Find below some useful information about Time Zone Conversion in oracle. Hope this would be helpful for many of them since all the real time projects that we work in follow different time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.