diff --git a/ChangeLog b/ChangeLog
index 6f367c8d1ca78eb4713567bb481f71049428f626_Q2hhbmdlTG9n..250b528255d59817f6cd74be5306075f79817647_Q2hhbmdlTG9n 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu May 31 12:38:08 PDT 2007 WIlliam Brack <wbrack@mmm.com.hk>
+
+	* libxslt/xslt.c: fixed obscure namespace problem related to
+	  exclude-result-prefix
+
 Mon May  7 00:14:28 HKT 2007 William Brack <wbrack@mmm.com.hk>
 
 	* libxslt/transform.c: fixed minor compilation warning; no change
diff --git a/libxslt/xslt.c b/libxslt/xslt.c
index 6f367c8d1ca78eb4713567bb481f71049428f626_bGlieHNsdC94c2x0LmM=..250b528255d59817f6cd74be5306075f79817647_bGlieHNsdC94c2x0LmM= 100644
--- a/libxslt/xslt.c
+++ b/libxslt/xslt.c
@@ -3469,7 +3469,7 @@
 	    }
 	    	     
 	    if ((cur->nsDef != NULL) && (style->exclPrefixNr > 0)) {
-		xmlNsPtr ns = cur->nsDef, prev = NULL, next;
+		xmlNsPtr ns = cur->nsDef, prev = NULL, next, rns;
 		xmlNodePtr root = NULL;
 		int i, moved;
 
@@ -3482,13 +3482,9 @@
 			    if ((ns->prefix != NULL) && 
 			        (xmlStrEqual(ns->href,
 					     style->exclPrefixTab[i]))) {
-				/*
-				 * Move the namespace definition on the root
-				 * element to avoid duplicating it without
-				 * loosing it.
-				 */
+				/* Remove the namespace from this node */
 				if (prev == NULL) {
 				    cur->nsDef = ns->next;
 				} else {
 				    prev->next = ns->next;
 				}
@@ -3490,10 +3486,23 @@
 				if (prev == NULL) {
 				    cur->nsDef = ns->next;
 				} else {
 				    prev->next = ns->next;
 				}
-				ns->next = root->nsDef;
-				root->nsDef = ns;
+				/*
+				 * If this prefix is not already present,
+				 * move the namespace definition on the root
+				 * element to avoid duplicating it without
+				 * loosing it.
+				 */
+				for (rns = root->nsDef; rns != NULL; rns = rns->next)
+				    if (xmlStrEqual(ns->prefix, rns->prefix))
+					break;
+				if (rns == NULL) {
+				    ns->next = root->nsDef;
+				    root->nsDef = ns;
+				}
+				else
+				    xmlFreeNs(ns);
 				moved = 1;
 				break;
 			    }