#84 Match on parent node in pattern fails

Michael Kay

A pattern of the form match="parent/child" will be
matched by a node whose parent has the wrong name.

If you want to apply a source fix, it's in class
net.sf.saxon.pattern.LocationPathPattern. Move the line

if (!nodeTest.matches(node.getItemType(),
node.getFingerprint())) return false;

which is the first line of method
public boolean matches(NodeInfo node, XSLTContext
context) throws XPathException {

so that it becomes the first line of method
protected boolean matches(NodeInfo node,
XPathContext context) throws XPathException {

The bug was introduced as a side-effect of the changes
to allow calls to current() within patterns.

(The first method is called for an "outer level" pattern
match. The second method is called to match a sub-
pattern, and differs in that it doesn't change the current()
node. The test on node type and name is being omitted
for subpatterns).

Reported by Mike Berrow [mberrow@pacbell.net]

Applies to 7.1 only. Source code fixed and tested
against the specific example, not yet regression tested.
Test suite not yet updated.


  • Michael Kay

    Michael Kay - 2002-07-03

    Logged In: YES

    Clarification: this problem does not affect the first or last
    element name in a pattern of the form A/B/C/D. In this
    example, any D will be matched that has A as a great-
    grandparent; but the tests on B and C are performed
    incorrectly. The bug therefore only affects patterns with at
    least three steps.

  • Michael Kay

    Michael Kay - 2002-08-28

    Logged In: YES

    Fixed in 7.2