some changes related to the new way of handling Result Value Tree, before

* tree.c xpath.c: some changes related to the new way of
  handling Result Value Tree, before 2.5.5
Daniel
diff --git a/ChangeLog b/ChangeLog
index 9a1df7a..191977a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Mar 24 19:38:05 CET 2003 Daniel Veillard <daniel@veillard.com>
+
+	* tree.c xpath.c: some changes related to the new way of 
+	  handling Result Value Tree, before 2.5.5
+
 Mon Mar 24 16:36:23 CET 2003 Daniel Veillard <daniel@veillard.com>
 
 	* configure.in NEWS: preparing release 2.5.5
diff --git a/tree.c b/tree.c
index 2186d51..67f4399 100644
--- a/tree.c
+++ b/tree.c
@@ -2967,6 +2967,14 @@
 	xmlFreeNsList((xmlNsPtr) cur);
 	return;
     }
+    if ((cur->type == XML_DOCUMENT_NODE) ||
+#ifdef LIBXML_DOCB_ENABLED
+	(cur->type == XML_DOCB_DOCUMENT_NODE) ||
+	(cur->type == XML_HTML_DOCUMENT_NODE)) {
+#endif
+	xmlFreeDoc((xmlDocPtr) cur);
+	return;
+    }
     while (cur != NULL) {
         next = cur->next;
 	/* unroll to speed up freeing the document */
@@ -4592,17 +4600,39 @@
                 return (ret);
             }
         case XML_ENTITY_NODE:
-        case XML_DOCUMENT_NODE:
-        case XML_HTML_DOCUMENT_NODE:
         case XML_DOCUMENT_TYPE_NODE:
         case XML_NOTATION_NODE:
         case XML_DTD_NODE:
         case XML_XINCLUDE_START:
         case XML_XINCLUDE_END:
+            return (NULL);
+        case XML_DOCUMENT_NODE:
 #ifdef LIBXML_DOCB_ENABLED
         case XML_DOCB_DOCUMENT_NODE:
 #endif
-            return (NULL);
+        case XML_HTML_DOCUMENT_NODE: {
+            xmlChar *tmp;
+	    xmlChar *res = NULL;
+
+	    cur = cur->children;
+	    while (cur!= NULL) {
+		if ((cur->type == XML_ELEMENT_NODE) ||
+		    (cur->type == XML_TEXT_NODE) ||
+		    (cur->type == XML_CDATA_SECTION_NODE)) {
+		    tmp = xmlNodeGetContent(cur);
+		    if (tmp != NULL) {
+			if (res == NULL)
+			    res = tmp;
+			else {
+			    res = xmlStrcat(res, tmp);
+			    xmlFree(tmp);
+			}
+		    }
+		}
+		cur = cur->next;
+	    }
+	    return(res);
+	}
         case XML_NAMESPACE_DECL: {
 	    xmlChar *tmp;
 
diff --git a/xpath.c b/xpath.c
index ee339de..916b103 100644
--- a/xpath.c
+++ b/xpath.c
@@ -3134,21 +3134,24 @@
 	case XPATH_XSLT_TREE:
 	    if ((val->nodesetval != NULL) &&
 		(val->nodesetval->nodeTab != NULL)) {
-		xmlNodePtr cur, top, tmp;
+		xmlNodePtr cur, tmp;
+		xmlDocPtr top;
 
 		ret->boolval = 1;
-		top =  xmlCopyNode(val->nodesetval->nodeTab[0], 0);
+		top =  xmlNewDoc(NULL);
+		top->name = (char *)
+		    xmlStrdup(val->nodesetval->nodeTab[0]->name);
 		ret->user = top;
 		if (top != NULL) {
-		    top->doc = (xmlDocPtr) top;
+		    top->doc = top;
 		    cur = val->nodesetval->nodeTab[0]->children;
 		    while (cur != NULL) {
-			tmp = xmlDocCopyNode(cur, (xmlDocPtr) top, 1);
-			xmlAddChild(top, tmp);
+			tmp = xmlDocCopyNode(cur, top, 1);
+			xmlAddChild((xmlNodePtr) top, tmp);
 			cur = cur->next;
 		    }
 		}
-		ret->nodesetval = xmlXPathNodeSetCreate(top);
+		ret->nodesetval = xmlXPathNodeSetCreate((xmlNodePtr) top);
 	    } else
 		ret->nodesetval = xmlXPathNodeSetCreate(NULL);
 	    /* Deallocate the copied tree value */
@@ -3279,8 +3282,6 @@
  */
 xmlChar *
 xmlXPathCastNodeToString (xmlNodePtr node) {
-    if ((node != NULL) && (node->type == XML_DOCUMENT_NODE))
-	node = xmlDocGetRootElement((xmlDocPtr) node);
     return(xmlNodeGetContent(node));
 }
 
@@ -3859,6 +3860,16 @@
     if (node == NULL)
 	return(0);
 
+    if (node->type == XML_DOCUMENT_NODE) {
+	tmp = xmlDocGetRootElement((xmlDocPtr) node);
+	if (tmp == NULL)
+	    node = node->children;
+	else
+	    node = tmp;
+
+	if (node == NULL)
+	    return(0);
+    }
 
     switch (node->type) {
 	case XML_COMMENT_NODE:
@@ -4270,6 +4281,10 @@
 		if (neq)
 		    continue;
                 return (1);
+	    } else if ((str2 == NULL) && (xmlStrEqual(str, BAD_CAST ""))) {
+		if (neq)
+		    continue;
+                return (1);
             } else if (neq) {
 		if (str2 != NULL)
 		    xmlFree(str2);