added coding to xsltCopyTree to copy namespaces (bug 139578). changed to
authorWilliam M. Brack <wbrack@src.gnome.org>
Thu, 1 Jul 2004 02:25:08 +0000 (02:25 +0000)
committerWilliam M. Brack <wbrack@src.gnome.org>
Thu, 1 Jul 2004 02:25:08 +0000 (02:25 +0000)
* libxslt/transform.c: added coding to xsltCopyTree to copy
  namespaces (bug 139578).
* tests/general/bug-128.out: changed to reflect above fix
* libxslt/xslt.c: minor change to an error message

ChangeLog
libxslt/transform.c
libxslt/xslt.c
tests/general/bug-128.out

index 995535a..ab235c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Jul  1 10:07:55 HKT 2004 William Brack <wbrack@mmm.com.hk>
+
+       * libxslt/transform.c: added coding to xsltCopyTree to copy
+         namespaces (bug 139578).
+       * tests/general/bug-128.out: changed to reflect above fix
+       * libxslt/xslt.c: minor change to an error message
+
 Wed Jun 30 18:41:20 CEST 2004 Daniel Veillard <daniel@veillard.com>
 
        * win32/Makefile.msvc win32/Makefile.mingw libexslt/Makefile.am
index 3a70da5..25c362c 100644 (file)
@@ -1010,16 +1010,30 @@ xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node,
         */
        if ((node->type == XML_ELEMENT_NODE) ||
            (node->type == XML_ATTRIBUTE_NODE)) {
+           xmlNsPtr *nsList, *cur, ns;
            if (node->ns != NULL)
                copy->ns = xsltGetNamespace(ctxt, node, node->ns, copy);
-           else if ((insert != NULL) && (insert->type == XML_ELEMENT_NODE) &&
-                    (insert->ns != NULL)) {
+           else if ((insert->type == XML_ELEMENT_NODE) && (insert->ns != NULL)) {
                xmlNsPtr defaultNs;
 
                defaultNs = xmlSearchNs(insert->doc, insert, NULL);
                if (defaultNs != NULL)
                    xmlNewNs(copy, BAD_CAST "", NULL);
            }
+           /*
+            * must also add in any new namespaces in scope for the node
+            */
+           nsList = xmlGetNsList(node->doc, node);
+           if (nsList != NULL) {
+               cur = nsList;
+               while (*cur != NULL) {
+                   ns = xmlSearchNsByHref(insert->doc, insert, (*cur)->href);
+                   if (ns == NULL)
+                       xmlNewNs(copy, (*cur)->href, (*cur)->prefix);
+                   cur++;
+               }
+               xmlFree(nsList);
+           }
        }
        if (node->nsDef != NULL) {
            if (literal)
index 85937bb..2445c76 100644 (file)
@@ -585,7 +585,7 @@ xsltGetInheritedNsList(xsltStylesheetPtr style,
                                                sizeof(xmlNsPtr));
                     if (ret == NULL) {
                         xmlGenericError(xmlGenericErrorContext,
-                                        "xmlGetNsList : out of memory!\n");
+                                        "xsltGetInheritedNsList : out of memory!\n");
                         return(0);
                     }
                     ret[nbns] = NULL;
@@ -604,7 +604,7 @@ xsltGetInheritedNsList(xsltStylesheetPtr style,
                                                       sizeof(xmlNsPtr));
                         if (ret == NULL) {
                             xmlGenericError(xmlGenericErrorContext,
-                                            "xmlGetNsList : realloc failed!\n");
+                                            "xsltGetInheritedNsList : realloc failed!\n");
                             return(0);
                         }
                     }
index 31a5e2e..fcd73db 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <test:data xmlns:test="http://www.example.org/test">
-  <test:a a="1"/>
-  <test:b b="1"/>
+  <test:a xmlns:xsl="http://www.w3.org/1999/XSL/Transform" a="1"/>
+  <test:b xmlns:xsl="http://www.w3.org/1999/XSL/Transform" b="1"/>
 </test:data>