Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 1st, 2006, 10:25 AM
kebabkongen@hotmail.com
Guest
 
Posts: n/a
Default 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

  #2  
Old December 1st, 2006, 12:45 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Using XSL to calculate time (t = hh:mi + mi)

kebabkongen@hotmail.com wrote:
Quote:
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/
  #3  
Old December 1st, 2006, 01:25 PM
fedro
Guest
 
Posts: n/a
Default Re: Using XSL to calculate time (t = hh:mi + mi)


Martin Honnen schrieb:
Quote:
kebabkongen@hotmail.com wrote:
Quote:
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 ?

  #4  
Old December 1st, 2006, 01:45 PM
kebabkongen@hotmail.com
Guest
 
Posts: n/a
Default Re: Using XSL to calculate time (t = hh:mi + mi)

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:
Quote:
Martin Honnen schrieb:
>
Quote:
kebabkongen@hotmail.com wrote:
>
Quote:
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 ?
  #5  
Old December 1st, 2006, 02:15 PM
fedro
Guest
 
Posts: n/a
Default Re: Using XSL to calculate time (t = hh:mi + mi)

kebabkongen@hotmail.com schrieb:

Quote:
<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.

  #6  
Old December 1st, 2006, 02:55 PM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: Using XSL to calculate time (t = hh:mi + mi)


<kebabkongen@hotmail.comwrote in message
news:1164970079.132517.69620@n67g2000cwd.googlegro ups.com...
Quote:
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


 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles