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

K

kebabkongen

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
 
M

Martin Honnen

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>
 
F

fedro

Martin said:
(e-mail address removed) 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 ?
 
K

kebabkongen

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:eek:therwise >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2))"/>
</xsl:eek:therwise>
</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:eek:therwise >
<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsl:eek:therwise>
</xsl:choose>

Thanks for help!

-Per Magnus
 
F

fedro

<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:eek:therwise >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2))"/>
</xsl:eek:therwise>
</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:eek:therwise >
<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsl:eek:therwise>
</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.
 
D

Dimitre Novatchev

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=v20020711152545&ms=220&l=codelib&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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top