The optimizer should not attempt loop-lifting on any expression that contains a reference to an assignable global variable (that is, a variable defined in XSLT with saxon:assignable="yes"). Loop-lifting typically occurs when an expression appears in a for-each loop or a predicate but has no dependency on the context node, or when it appears in the body of a "for" expression and has no dependency on the range variable; such an expression is evaluated outside the loop (or on the first time round the loop) to prevent repeated and redundant evaluation of the same expression.
The effect of doing loop-lifting on such an expression is that it can use the value of the global variable as it was before entry to the loop.
A patch is being raised in Subversion to prevent this happening. It affects modules VariableReference, StaticProperty, and PromotionOffer.