[XSLT 2.0]Extension functions with side-effects and optimizations

Hi,

      On the topic of extension functions with side-effects, the spec
states :

"There is no prohibition on calling extension functions that have
side-effects (for example, an extension function that writes data to a
file). However, the order of execution of XSLT instructions is not defined
in this specification, so the effects of such functions are unpredictable."

      An extension function with side-effects can also be utilized in other
ways. For example, a global variable can be defined as a child of the
xsl:stylesheet element and the "select" can invoke the extension function.
The side-effect in question could be something like the creation of a file
indicating that XSLT processing has been done on something else. One of the
major XSLT (1.0) processors around optimizes such global variables away if
the value of the variable isnt being used for anything. I had some
correspondance with one of its maintainer recently, and this is what he had
to say on the topic :

"That's sorta the nature of the beast, I'm afraid. XSLT is a functional
language, and that means that stuff can get executed out-of-sequence or
optimized away... and that's only going to become more common as we
continue to work on improving stylesheet efficiency. Extensions with
side-effects are problematic at best; they really should be thought of as
extension Functions in the pure sense of the term.

The only way to force evaluation of a variable is to use that variable's
value. There are a few kluges that folks have come up with to use it and
throw it away, but it can be tricky to find one that is guaranteed not to
be optimized out in the future."

      This is a situation that doesnt seem to be explicitly addressed in
the 2.0 spec. While out of order execution of extension functions may be
kosher, is it ok to completely optimize away the variable itself?

Thanks,
Kenneth Stephen

T/L 793-6462
(512)823-6462

Received on Friday, 2 January 2004 23:57:12 UTC