#93 position()!=last() in pattern fails

v6.5.2
closed
Michael Kay
5
2014-12-16
2002-09-03
Michael Kay
No

A match pattern containing the predicate [position()!=last
()]
or [position()<last()] gives the wrong answer: if
selects the nodes where position()=last(), and fails to
select those where position()!=last().

Applies to 6.5.2, 7.1, and 7.2.

Circumvention: declare a higher-priority template rule
with the pattern [position()=last()], and leave this filter off
the rule for matching other nodes.

Source fix (tested on Saxon 7.2):

(a) in expr.IsLastExpression, add the method

public boolean getCondition() {
    return condition;
}

(b) in pattern.LocationPathPattern, around line 108 in
Saxon 7.2 or line 90 in Saxon 6.5.2, change the test:

    if (nodeTest.getItemType() == Type.ELEMENT &&
            numberOfFilters==1 &&
            filters[0] instanceof IsLastExpression)

to:

    if (nodeTest.getItemType() == Type.ELEMENT &&
            numberOfFilters==1 &&
            filters[0] instanceof IsLastExpression &&
            ((IsLastExpression)filters[0]).getCondition())

Source code fixed in both branches.

Test case added: pos64

Discussion

  • Michael Kay
    Michael Kay
    2002-11-18

    Logged In: YES
    user_id=251681

    Cleared in 7.3