Saxon evaluating functions and variables unnecessarily

Having trouble installing Oxygen? Got a bug to report? Post it all here.
whyme
Posts: 93
Joined: Fri Mar 08, 2013 8:58 am

Saxon evaluating functions and variables unnecessarily

Post by whyme »

When I use Saxon 9.6 to run a transformation, and it comes across a statement such as this...

Code: Select all

<value-of select ="if ($a) then $a else $b"/>
...it is evaluating $b whether or not $a is true. For a full discussion, along with result discrepancies, see here:
http://stackoverflow.com/questions/3207 ... alculation

Any suggestions on how to rectify this? Thanks!
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Saxon evaluating functions and variables unnecessarily

Post by adrian »

Hi,

You haven't mentioned if you are running this in Oxygen as a transformation scenario or in the XSLT debugger. I'm guessing it's the latter, due to the fact that variables are eagerly evaluated only in the debugger (tracing enabled).
Note that this doesn't have anything to do with the expression used, it's only the fact that you are using a variable there and all used variables are evaluated eagerly when debugging.
If you want consistent results, don't use variables and expect them to be lazily evaluated, use functions instead. e.g.

Code: Select all

<value-of select ="if ($a) then $a else eg:very-long-func()"/>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply