New Bug and Fix: Repeat Eval in GlobalParam

  • Gunther Schadow

    Gunther Schadow - 2004-12-08

    Between Saxon 7.6 and Saxon 8.1.1 a new bug has emerged. This one is rather subtle but I think it is clearly a bug. Saxon evaluates param expressions repeatedly, when it should only evaluate them once. Here is an example:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:transform version="1.0" xmlns:xsl="" xmlns:sys="java:java.lang.System" xmlns:ps="">

    <xsl:param name="stream" select="(ps:println(sys:err(),'param evaluated'),sys:err())[last()]"/>

    <xsl:template match="/">
    <xsl:value-of select="ps:println($stream,'pong 1')"/>
    <xsl:value-of select="ps:println($stream,'pong 2')"/>


    The output should be

    param evaluated
    pong 1
    pong 2

    as it happens with saxon 7.6. But with saxon 8.1.1 it is:

    param evaluated
    pong 1
    param evaluated
    pong 2

    Interrestingly this happens only with global parameters, not with local parameters nor with local or global variables. So, I expect this bug sits somewhere in the instruct/ ...

    And BINGO here is the bug:

    You say:

        if (wasSupplied) {
            return b.getGlobalVariableValue(this);
        } else {
            // This is the first reference to a global variable; try to evaluate it now.

    where you never check whether you already have it evaluated. Change this code to

        Value v = b.getGlobalVariableValue(this);
        if (wasSupplied || v != null) {
            return v;
        } else {
            // This is the first reference to a global variable; try to evaluate it now.

    and everything will be fine again.

    I'll reply to your recent mail soon. If I reply by email, will it get to the email list that you named even if I'm not signed up?


    • Michael Kay

      Michael Kay - 2004-12-08

      Thanks. It's not actually a conformance issue - processors are allowed to evaluate variables repeatedly, and if doing so calls extension functions that have side effects, so be it - however, it's a coding error and I will fix it.

      Michael Kay


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks