Thanks, this is a new bug. I've put an explanation at:
and I've tested a patch which is going into Subversion.
As a workaround, don't use temporary tree variables! Either use the select attribute of xsl:variable, or use an "as" attribute to define the type, e.g.
<xsl:variable name="x" as="xs:integer">
    <xsl:when test="expr">
      <xsl:sequence select="42"/>
Michael Kay

From: [] On Behalf Of Matt Thomas
Sent: 15 January 2007 17:00
Subject: [saxon] ClassCastException with xsl:choose in 8.8b

I recently upgraded to Saxon 8.8b (Java) from 8.7 and started getting this error message:

java.lang.ClassCastException: net.sf.saxon.value.StringValue
    at net.sf.saxon.expr.ArithmeticExpression$NumericArithmetic.doArithmetic (
    at net.sf.saxon.expr.ArithmeticExpression$NumericArithmetic.evaluateItem(
    at net.sf.saxon.instruct.SimpleContentConstructor.evaluateItem( :199)
    at net.sf.saxon.instruct.ValueOf.processLeavingTail(
    at net.sf.saxon.expr.LetExpression.processLeavingTail(
    at net.sf.saxon.instruct.Template.applyLeavingTail (
    at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(
    at net.sf.saxon.instruct.ApplyTemplates.defaultAction(
    at net.sf.saxon.instruct.ApplyTemplates.applyTemplates (
    at net.sf.saxon.Controller.transformDocument(
    at net.sf.saxon.Controller.transform(
    at net.sf.saxon.Transform.processFile( :828)
    at net.sf.saxon.Transform.doTransform(
    at net.sf.saxon.Transform.main(

I reduced the problem down to this in the stylesheet:

<xsl:variable name="a">
        <xsl:when test="1=1">4</xsl:when>

<xsl:value-of select="$a - 1"/>

Using an <xsl:sequence select="4"/> inside the when statement works properly (and I should have done that in the first place). I was just wondering if this should be throwing a Java ClassCastException?

Matt Thomas