Page 1 of 1

Saxon evaluating functions and variables unnecessarily

Posted: Tue Aug 18, 2015 10:35 pm
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!

Re: Saxon evaluating functions and variables unnecessarily

Posted: Fri Aug 21, 2015 5:58 pm
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