XSLT does not define the order of execution of instructions or expressions. Just because the declaration of the $start variable is nearer the top of your stylesheet than the declaration of $end doesn't mean it will be evaluated first.

What Saxon does in practice (usually) is to evaluate a variable when its value is first needed. Your second test has the desired effect because Saxon executes xsl:message instructions in the order you are intuitively expecting; but it is under no obligation to do so so (and when you start introducing multithreading, which happens with xsl:result-document in Saxon-EE, even that goes out of the window).

Michael Kay
Saxonica


On 8 Nov 2013, at 13:30, philippe.favrais@continental-corporation.com wrote:

Hello,

I am trying to display the time spent in a xsl:template and i get the following behavior which i can't explain (i am using saxon_b)
Could someone explain me why do i need to display the variable $start to get the correct duration?

In the test 1: (which do not give me the result i expect)
at the beging of the template I initialize a variable $start and at the end of the template another variable $end. When displaying the result i get 0.  Why ?

In the test 2: (which give me the result i expect)
i do the same as test 1, except that i display the variable $start and in that can i get the correct result


Test 1
   <xsl:template name="Com">
     <xsl:variable name="start" select="system:currentTimeMillis()" as="xs:integer"/>
     <AUTOSAR>
         <ShortName><xsl:value-of select="lookup:defaults($currentModuleName, 'TOP-LEVEL-PACKAGE')"/></ShortName>
         <Com>
            <ShortName><xsl:value-of select="lookup:ecuModuleConfigName($currentModuleName)"/></ShortName>
            <xsl:apply-templates/>
         </Com>
      </AUTOSAR>
             <xsl:variable name="end" select="system:currentTimeMillis()" as="xs:integer"/>
             <xsl:variable name="duration" select="($end - $start)" as="xs:integer"/>
          <xsl:message>Elapsed time to generate pseudoecuconfig file of <xsl:value-of select="$currentModuleName"/> module : <xsl:value-of select="$duration"/> ms</xsl:message>
  </xsl:template>

Message Output :
Elapsed time to generate pseudoecuconfig file of Com module : 0 ms



Test 2:
   <xsl:template name="Com">
     <xsl:variable name="start" select="system:currentTimeMillis()" as="xs:integer"/>
     <xsl:message>Start : <xsl:value-of select="$start"/></xsl:message>
     <AUTOSAR>
         <ShortName><xsl:value-of select="lookup:defaults($currentModuleName, 'TOP-LEVEL-PACKAGE')"/></ShortName>
         <Com>
            <ShortName><xsl:value-of select="lookup:ecuModuleConfigName($currentModuleName)"/></ShortName>
            <xsl:apply-templates/>
         </Com>
      </AUTOSAR>
             <xsl:variable name="end" select="system:currentTimeMillis()" as="xs:integer"/>
             <xsl:variable name="duration" select="($end - $start)" as="xs:integer"/>
          <xsl:message>Elapsed time to generate pseudoecuconfig file of <xsl:value-of select="$currentModuleName"/> module : <xsl:value-of select="$duration"/> ms</xsl:message>
  </xsl:template>

Message output :
Start : 1383905589145
Elapsed time to generate pseudoecuconfig file of Com module : 68971 ms


Thank you in advance
Philippe------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help