integrated a couple of fixes and a new API function

* parser.c include/libxml/parserInternals.h tree.c: integrated
  a couple of fixes and a new API function xmlSetEntityReferenceFunc()
  from Keith Isdale and dedicated to xsldbg the XSLT debugger.
Daniel
diff --git a/tree.c b/tree.c
index feabe8b..28f4490 100644
--- a/tree.c
+++ b/tree.c
@@ -2642,9 +2642,13 @@
     ret->parent = target;
     
     if ((cur->ns != NULL) && (target != NULL)) {
-        xmlNsPtr ns;
-
+      xmlNsPtr ns;
+      if (target->doc) 
 	ns = xmlSearchNs(target->doc, target, cur->ns->prefix);
+      else if (cur->doc)  /* target may not yet have a doc : KPI */
+	ns = xmlSearchNs(cur->doc, target, cur->ns->prefix);       
+      else
+	ns = NULL;
 	ret->ns = ns;
     } else
         ret->ns = NULL;
@@ -2786,6 +2790,9 @@
 		     xmlBufferContent(node->content),
 		     xmlBufferLength(node->content));
 #endif
+    }else{
+      if (node->type == XML_ELEMENT_NODE)
+        ret->content = (void*)(long) node->content;
     }
     if (parent != NULL)
         xmlAddChild(parent, ret);