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

Subject: Re: [xsl] difference between an integer and current-dateTime()
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 31 Mar 2020 08:04:15 -0000
Am 31.03.2020 um 07:01 schrieb Mukul Gandhi gandhi.mukul@xxxxxxxxx:
On Mon, Mar 30, 2020 at 5:31 PM Michael Kay mike@xxxxxxxxxxxx
<mailto:mike@xxxxxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:

I now have following XSLT stylesheet with me,

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

B B <xsl:output method="text"/>

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

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

B B B B B xs:dayTimeDuration('PT' || $secsSinceEpoch || 'S')"

as="xs:dateTime"/>
 B  B  B  B <xsl:variable name="diffDTduration" select="current-dateTime()
-
$epochDateTime" as="xs:dayTimeDuration"/>
 B  B  B  B <xsl:value-of
select="fn0:secsFromdiffDTduration($diffDTduration) div 60"/>
 B  B  </xsl:template>

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

 B  B  B  B <xsl:variable name="totalSecs" select="$diffDTduration div
xs:dayTimeDuration('PT1S')" />
 B  B  B  B <xsl:sequence select="$totalSecs"/>
 B  B  </xsl:function>

</xsl:stylesheet>

This gives me an output,

F:\>java -classpath SaxonHE10-0J\saxon-he-10.0.jar
net.sf.saxon.Transform -s:trf1.xsl -xsl:trf1.xsl secsSinceEpoch=1585633856
-53.430133333333333333333

I was expecting <xsl:value-of
select="fn0:secsFromdiffDTduration($diffDTduration) div 60"/> to return
me about 1 hr. But that isn't. Any thoughts?


In general, if you want the difference in seconds, I would suggest to use
  div xs:dayTimeDuration('PT1S')
for minutes
  div xs:dayTimeDuration('PT1M')
or for hours
  div xs:dayTimeDuration('PT1H')

As for the values, which dateTime is 1585633856?

Current Thread