fixing #96925 wich was also dependant on the processing of parsed

* parser.c xpath.c: fixing #96925 wich was also dependant on the
  processing of parsed entities, and XPath computation on sustitued
  entities.
* testXPath.c: make sure entities are substitued.
Daniel
diff --git a/xpath.c b/xpath.c
index 5da280f..28c8a36 100644
--- a/xpath.c
+++ b/xpath.c
@@ -1367,6 +1367,10 @@
     if (node1 == node2->next)
 	return(-1);
 
+#if 0
+    Unfortunately this does not work. Line number in entities reset
+    to 1 within the entity :-(
+
     /*
      * Speedup using line numbers if availble.
      */
@@ -1381,7 +1385,7 @@
 	if (l1 > l2)
 	    return(-1);
     }
-
+#endif
     /*
      * compute depth to root
      */
@@ -5169,13 +5173,27 @@
     }
 
     if (cur->children != NULL) {
-    	if (cur->children->type != XML_ENTITY_DECL)
-	    return(cur->children);
+	/*
+	 * Do not descend on entities declarations
+	 */
+    	if (cur->children->type != XML_ENTITY_DECL) {
+	    cur = cur->children;
+	    /*
+	     * Skip DTDs
+	     */
+	    if (cur->type != XML_DTD_NODE)
+		return(cur);
+	}
     }
 
     if (cur == ctxt->context->node) return(NULL);
 
-    if (cur->next != NULL) return(cur->next);
+    while (cur->next != NULL) {
+	cur = cur->next;
+	if ((cur->type != XML_ENTITY_DECL) &&
+	    (cur->type != XML_DTD_NODE))
+	    return(cur);
+    }
     
     do {
         cur = cur->parent;