xsl-list
[Top] [All Lists]

Re: [xsl] difference between an integer and current-dateTime()

2020-03-30 08:20:23
So you really missed this simple solution:
https://stackoverflow.com/a/3468123/36305

 ( current-dateTime() - xs:dateTime('1970-01-01T00:00:00') )
 div
   xs:dayTimeDuration('PT1S')


On Mon, Mar 30, 2020 at 4:51 AM Mukul Gandhi 
gandhi(_dot_)mukul(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

On Mon, Mar 30, 2020 at 12:23 PM Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Am 30.03.2020 um 08:49 schrieb Mukul Gandhi 
gandhi(_dot_)mukul(_at_)gmail(_dot_)com:



Here you have used the wrong prefix "xs" again, instead you want
     <xsl:sequence select="$totalSecs"/>
no?


The following finally works for me,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                         xmlns:xs="http://www.w3.org/2001/XMLSchema";
                         xmlns:fn0="http://fns0";
                         exclude-result-prefixes="xs fn0"
                         version="3.0">

    <xsl:output method="text"/>

    <xsl:param name="secsSinceEpoch" as="xs:integer"/>

    <xsl:template match="/">
       <xsl:variable name="epochDateTime"
select="xs:dateTime('1970-01-01T00:00:00Z') +

       xs:dayTimeDuration('PT' || $secsSinceEpoch || 'S')"
                                          as="xs:dateTime"/>
       <xsl:variable name="diffDTduration" select="current-dateTime() -
$epochDateTime" as="xs:dayTimeDuration"/>
       <xsl:value-of select="fn0:minsFromdiffDTduration($diffDTduration)"/>
    </xsl:template>

    <xsl:function name="fn0:minsFromdiffDTduration" as="xs:decimal">
       <xsl:param name="diffDTduration" as="xs:dayTimeDuration"/>

       <xsl:variable name="yrsDuration"
select="years-from-duration($diffDTduration)"/>
       <xsl:variable name="mnthsDuration"
select="months-from-duration($diffDTduration)"/>
       <xsl:variable name="daysDuration"
select="days-from-duration($diffDTduration)"/>
       <xsl:variable name="hrsDuration"
select="hours-from-duration($diffDTduration)"/>
       <xsl:variable name="mnsDuration"
select="minutes-from-duration($diffDTduration)"/>
       <xsl:variable name="secsDuration"
select="seconds-from-duration($diffDTduration)"/>

       <xsl:variable name="totalSecs" select="$yrsDuration * 365 * 24 * 60
+ $mnthsDuration * 30 * 24 * 60 +

$daysDuration * 24 * 60 + $hrsDuration * 60 + $mnsDuration +

$secsDuration div 60" />
       <xsl:sequence select="$totalSecs"/>

    </xsl:function>

</xsl:stylesheet>

Many thanks.


--
Regards,
Mukul Gandhi
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
email <>)



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>