[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How to output the start execution time and the end execution time?

Subject: Re: [xsl] How to output the start execution time and the end execution time?
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 6 Sep 2014 16:30:35 -0000

Hi Roger,

Functions and constructs in XSLT and XPath are stable (barring a few
exceptions). Calling a function with the same argument twice will yield the
same result for both calls. The functions current-time(), current-dateTime()
and current-date() will therefor always return the same time (with a slight
caveat for static and dynamic evaluation phases, but let's not digress).

The only way out here is extension functions, or a trick with XSLT 3.0 using
streaming, because the xsl:stream instruction is deemed non-stable (i.e., it
will re-invoke the url at the href argument each time it is called). Whether
an extension function helps depends whether your processor allows non-stable
extension functions, but I believe most, if not all, processors do.

Here's a (workable) trick that works with all XSLT 3.0 processors, however you
might want to choose a local resource instead that returns the current
date-time, for performance reasons.

<xsl:mode streamable="yes" name="time" on-no-match="shallow-skip" >

<!-- may need an actual argument to force re-evaluation -->
<xsl:function name="my:current-time">
  <xsl:stream href="http://time.is">
    <xsl:apply-templates mode="time" />

<!-- match the element that contains the time -->
<xsl:template match="div[@id = 'twd']">
    <xsl:value-of select="." />

<xsl:template match="/">
     <xsl:value-of select="my:current-time()" />
     ... do the processing ...
     <xsl:value-of select="my:current-time()" />

Note: the page http://time.is currently does not deliver proper XML (and on my
search for a time server that did deliver proper XML or even proper XHTML I
did not find any). If you can convince your processor not to cache the result
of unparsed-text, you can use the following with the same server as a
workaround (ugly, but it shows the principle):

<xsl:value-of select="replace(unparsed-text('http://time.is/'),
'.+twd&quot;&gt;([^&lt;]+).*', '$1', 'sm')" />


> -----Original Message-----
> From: Costello, Roger L. costello@xxxxxxxxx [mailto:xsl-list-
> service@xxxxxxxxxxxxxxxxxxxxxx]
> Sent: Saturday, September 06, 2014 11:47 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] How to output the start execution time and the end execution
> time?
> Hi Folks,
> I would like to:
> 1. Output the time that my XSLT program starts processing 2. Do the
> processing 3. Output the time that my XSLT program finishes processing
> This doesn't work:
>     <xsl:template match="/">
>         <xsl:value-of select="current-time()" />
>         ... do the processing ...
>         <xsl:value-of select="current-time()" />
>     </xsl:template>
> What is the correct way to accomplish this?
> /Roger

Current Thread