--- /home/cpdev/src/classpath/gnu/xml/xpath/Selector.java	2006-01-16 17:32:46.000000000 +0000
+++ gnu/xml/xpath/Selector.java	2006-01-13 17:34:15.000000000 +0000
@@ -90,7 +90,7 @@
     if (len > 0)
       tests.toArray(this.tests);
     else
-      this.tests[0] = new NodeTypeTest((short) 0);
+      this.tests[0] = new NameTest(null, true, true);
     if (axis == NAMESPACE && this.tests[0] instanceof NameTest)
       {
         NameTest nt = (NameTest) this.tests[0];
@@ -108,14 +108,6 @@
 
   public boolean matches(Node context)
   {
-    // If called directly, selector is the top level of the path
-    return matches(context,
-                   getContextPosition(context),
-                   getContextSize(context));
-  }
-  
-  boolean matches(Node context, int pos, int len)
-  {
     short nodeType = context.getNodeType();
     switch (axis)
       {
@@ -133,11 +125,19 @@
       default:
         return false;
       }
-    for (int j = 0; j < tests.length && len > 0; j++)
+    int tlen = tests.length;
+    if (tlen > 0)
       {
-        Test test = tests[j];
-        if (!test.matches(context, pos, len))
-          return false;
+        int pos = getContextPosition(context);
+        int len = getContextSize(context);
+        if (len == 0)
+          System.err.println("WARNING: context size is 0");
+        for (int j = 0; j < tlen && len > 0; j++)
+          {
+            Test test = tests[j];
+            if (!test.matches(context, pos, len))
+              return false;
+          }
       }
     return true;
   }
@@ -147,10 +147,7 @@
     int pos = 1;
     for (ctx = ctx.getPreviousSibling(); ctx != null;
          ctx = ctx.getPreviousSibling())
-      {
-        if (tests[0].matches(ctx, 1, 1))
-          pos++;
-      }
+      pos++;
     return pos;
   }
 
@@ -164,16 +161,10 @@
     int count = 1;
     Node sib = ctx.getPreviousSibling();
     for (; sib != null; sib = sib.getPreviousSibling())
-      {
-        if (tests[0].matches(ctx, 1, 1))
-          count++;
-      }
+      count++;
     sib = ctx.getNextSibling();
     for (; sib != null; sib = sib.getNextSibling())
-      {
-        if (tests[0].matches(ctx, 1, 1))
-          count++;
-      }
+      count++;
     return count;
   }
 
