Thanks, now fixed.  (Saxon 9.1 is attempting to preevaluate constant filter expressions at compile time, and isn't getting the dependency analysis of the predicate right).
Michael Kay

From: [] On Behalf Of Rademacher, Gunther
Sent: 26 May 2008 16:09
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: [saxon] NPE while compiling XQuery predicate on an external variable

This occurs with Saxon while compiling

    declare variable $v external;

The stacktrace is

            at net.sf.saxon.instruct.GlobalParam.evaluateVariable(
            at net.sf.saxon.expr.VariableReference.evaluateVariable(
            at net.sf.saxon.expr.FilterExpression.iterate(
            at net.sf.saxon.expr.FilterExpression.tryEarlyEvaluation(
            at net.sf.saxon.expr.FilterExpression.optimize(
            at net.sf.saxon.query.XQueryExpression.<init>(
            at net.sf.saxon.query.QueryParser.makeXQueryExpression(
            at net.sf.saxon.query.StaticQueryContext.compileQuery(
            at net.sf.saxon.query.StaticQueryContext.compileQuery(
            at net.sf.saxon.Query.compileQuery(
            at net.sf.saxon.Query.doQuery(
            at net.sf.saxon.Query.main(

Best regards,

Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany, – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/ Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), David Broadbent, Mark Edwards, Dr. Peter Kürpick,Arnd Zinnhardt; - Aufsichtsratsvorsitzender/ Chairman of the Supervisory Board: Frank F. Beelitz -