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

Discussion in 'XML' started by kebabkongen@hotmail.com, Dec 1, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Dec 1, 2006
    #2
    1. Advertising

  3. fedro Guest

    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 ?
    fedro, Dec 1, 2006
    #3
  4. Guest

    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

    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 ?
    , Dec 1, 2006
    #4
  5. fedro Guest

    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: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.
    fedro, Dec 1, 2006
    #5
  6. <> wrote in message
    news:...
    > 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
    Dimitre Novatchev, Dec 1, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,585
    A. Bolmarcich
    May 27, 2005
  2. Replies:
    2
    Views:
    9,244
    Martin Honnen
    Sep 5, 2006
  3. flamesrock
    Replies:
    8
    Views:
    435
    Hendrik van Rooyen
    Nov 24, 2006
  4. Manish_Ganvir
    Replies:
    13
    Views:
    1,555
    Keith Thompson
    Feb 14, 2005
  5. Ruwan Budha
    Replies:
    4
    Views:
    1,069
    Kirk Haines
    Mar 9, 2011
Loading...

Share This Page