some enhancement for fixing bug 142768 added regression test for this bug
authorWilliam M. Brack <wbrack@src.gnome.org>
Wed, 30 Jun 2004 04:29:32 +0000 (04:29 +0000)
committerWilliam M. Brack <wbrack@src.gnome.org>
Wed, 30 Jun 2004 04:29:32 +0000 (04:29 +0000)
* libxslt/namespaces: some enhancement for fixing bug 142768
* tests/namespaces/Makefile.am, tests/namespaces/tst6*:
  added regression test for this bug

ChangeLog
libxslt/namespaces.c
tests/namespaces/Makefile.am
tests/namespaces/tst6.out [new file with mode: 0644]
tests/namespaces/tst6.xml [new file with mode: 0644]
tests/namespaces/tst6.xsl [new file with mode: 0644]

index 32532b6..52ba365 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Jun 30 12:28:34 HKT 2004 William Brack <wbrack@mmm.com.hk>
+
+       * libxslt/namespaces: some enhancement for fixing bug 142768
+       * tests/namespaces/Makefile.am, tests/namespaces/tst6*:
+         added regression test for this bug
+
 Tue Jun 29 09:23:03 CEST 2004 Daniel Veillard <daniel@veillard.com>
 
        * Makefile.am examples/xsltICUSort.c: seems I never commited to CVS
index 8ed2bb2..f8a62cc 100644 (file)
@@ -371,23 +371,32 @@ xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns,
     if (URI == NULL)
        URI = ns->href;
 
+    /*
+     * If the parent is an XML_ELEMENT_NODE, and has the "equivalent"
+     * namespace as ns (either both default, or both with a prefix
+     * with the same href) then return the parent's ns record
+     */
     if ((out->parent != NULL) &&
        (out->parent->type == XML_ELEMENT_NODE) &&
        (out->parent->ns != NULL) &&
+       (((out->parent->ns->prefix == NULL) && (ns->prefix == NULL)) ||
+        ((out->parent->ns->prefix != NULL) && (ns->prefix != NULL))) &&
        (xmlStrEqual(out->parent->ns->href, URI)))
        ret = out->parent->ns;
     else {
-       if (ns->prefix != NULL) {
-           ret = xmlSearchNs(out->doc, out, ns->prefix);
-           if ((ret == NULL) || (!xmlStrEqual(ret->href, URI))) {
-               ret = xmlSearchNsByHref(out->doc, out, URI);
-           }
-       } else {
+        /*
+        * do a standard namespace search for ns in the output doc
+        */
+        ret = xmlSearchNs(out->doc, out, ns->prefix);
+       /*
+        * if the search fails and it's not for the default prefix
+        * do a search by href
+        */
+       if ((ret == NULL) && (ns->prefix != NULL))
            ret = xmlSearchNsByHref(out->doc, out, URI);
        }
-    }
 
-    if (ret == NULL) {
+    if (ret == NULL) { /* if no success and an element node, create the ns */
        if (out->type == XML_ELEMENT_NODE)
            ret = xmlNewNs(out, URI, ns->prefix);
     }
index 1964bc0..229e0a1 100644 (file)
@@ -9,8 +9,9 @@ EXTRA_DIST = \
     tst.xml tst.xsl tst.out \
     tst2.xml tst2.xsl tst2.out \
     tst3.xml tst3.xsl tst3.out \
-    tst4.xml tst4.xsl tst4.out
+    tst4.xml tst4.xsl tst4.out \
 #    tst5.xml tst5.xsl tst5.out
+    tst6.xml tst6.xsl tst6.out
 
 all:
 
diff --git a/tests/namespaces/tst6.out b/tests/namespaces/tst6.out
new file mode 100644 (file)
index 0000000..31208ad
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<foo xmlns="urn:foo" xmlns:foo="urn:foo" xmlns:foo2="urn:foo2">
+  <bar>hello</bar>
+  <foo:baz>phaw</foo:baz>
+  <foo:bling xmlns="urn:foo2">
+    <bar2>hello2</bar2>
+  </foo:bling>
+  <bar>hello</bar>
+  <foo:baz>phaw</foo:baz>
+  <bling xmlns="urn:foo2">
+    <bar2>hello2</bar2>
+  </bling>
+</foo>
diff --git a/tests/namespaces/tst6.xml b/tests/namespaces/tst6.xml
new file mode 100644 (file)
index 0000000..7cfad8b
--- /dev/null
@@ -0,0 +1,12 @@
+<foo xmlns="urn:foo" xmlns:foo="urn:foo" xmlns:foo2="urn:foo2">
+  <bar>hello</bar>
+  <foo:baz>phaw</foo:baz>
+  <foo:bling xmlns="urn:foo2">
+    <bar2>hello2</bar2>
+  </foo:bling>
+  <bar>hello</bar>
+  <foo:baz>phaw</foo:baz>
+  <bling xmlns="urn:foo2">
+    <bar2>hello2</bar2>
+  </bling>
+</foo>
diff --git a/tests/namespaces/tst6.xsl b/tests/namespaces/tst6.xsl
new file mode 100644 (file)
index 0000000..a2d4af1
--- /dev/null
@@ -0,0 +1,7 @@
+<xsl:transform
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  version="1.0">
+  <xsl:template match="/">
+    <xsl:copy-of select="."/>
+  </xsl:template>     
+</xsl:transform>