Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using XSL to calculate time (t = hh:mi + mi)

Reply
Thread Tools

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

 
 
kebabkongen@hotmail.com
Guest
Posts: n/a
 
      12-01-2006
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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-01-2006
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/
 
Reply With Quote
 
 
 
 
fedro
Guest
Posts: n/a
 
      12-01-2006

Martin Honnen schrieb:

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

 
Reply With Quote
 
kebabkongen@hotmail.com
Guest
Posts: n/a
 
      12-01-2006
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>
<xsltherwise >
<xsl:value-of
select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
60)+number(substring(nr/st,1,2))"/>
</xsltherwise>
</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>
<xsltherwise >
<xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
mod 60"/>
</xsltherwise>
</xsl:choose>

Thanks for help!

-Per Magnus

fedro wrote:
> Martin Honnen schrieb:
>
> > 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 ?


 
Reply With Quote
 
fedro
Guest
Posts: n/a
 
      12-01-2006
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>
> <xsltherwise >
> <xsl:value-of
> select="floor((number(substring(nr/st,4,2))+number(nr/ln)) div
> 60)+number(substring(nr/st,1,2))"/>
> </xsltherwise>
> </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>
> <xsltherwise >
> <xsl:value-of select="(number(substring(nr/st,4,2))+number(nr/ln))
> mod 60"/>
> </xsltherwise>
> </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.

 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      12-01-2006

<> wrote in message
news: 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert time to ruby time to calculate the time difference. Ruwan Budha Ruby 4 03-09-2011 04:43 PM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
xsl:sort using an xsl:variable as the sort key jobooker@gmail.com XML 2 09-05-2006 03:51 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
How to calculate size of an int without using the sizeof operator but using bitwise operator Manish_Ganvir C Programming 13 02-14-2005 07:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57