The optimizer calculates the static cardinality of an xsl:if instruction incorrectly, discounting the possibility that it may return an empty sequence.
One observed effect of this is that evaluation of the following variable declaration (which occurs in Docbook) generates the spurious error
Error on line 352 of ...docbook/base/html/graphics.xsl:
XPTY0004: Cast does not allow an empty sequence
The code is
and it has failed because the optimizer generated an internal "cast to xs:untypedAtomic" expression that did not allow for the possibility that the result of the xsl:if would be an empty sequence.
A patch to module net.sf.saxon.instruct.Choose is being placed in Subversion.