- libxslt/templates.c libxslt/transform.c: fixed bug #54446
authorDaniel Veillard <veillard@src.gnome.org>
Fri, 11 May 2001 17:15:46 +0000 (17:15 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Fri, 11 May 2001 17:15:46 +0000 (17:15 +0000)
  about attribute being generated twice. Fixed a number of related
  bugs on attributes handling.
- tests/REC/test-7.1.4.out: this changed an attribute generation
  order
- tests/docs/bug-27-.xml tests/general/bug-27-.*: added test
Daniel

ChangeLog
libxslt/templates.c
libxslt/transform.c
tests/REC/test-7.1.4.out
tests/docs/Makefile.am
tests/docs/bug-27-.xml [new file with mode: 0644]
tests/general/Makefile.am
tests/general/bug-27-.out [new file with mode: 0644]
tests/general/bug-27-.xsl [new file with mode: 0644]

index 4592ec6..e9c2304 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Fri May 11 19:12:26 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * libxslt/templates.c libxslt/transform.c: fixed bug #54446
+         about attribute being generated twice. Fixed a number of related
+         bugs on attributes handling.
+       * tests/REC/test-7.1.4.out: this changed an attribute generation
+         order
+       * tests/docs/bug-27-.xml tests/general/bug-27-.*: added test
+
 Fri May 11 17:08:14 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * libxslt/templates.c: fixed bug #54451 on escaped curly brackets
index 089dad4..7ce01be 100644 (file)
@@ -315,6 +315,7 @@ xsltEvalStaticAttrValueTemplate(xsltStylesheetPtr style, xmlNodePtr node,
 xmlAttrPtr
 xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target,
                        xmlAttrPtr cur) {
+    xmlNsPtr ns;
     xmlAttrPtr ret;
     if ((ctxt == NULL) || (cur == NULL))
        return(NULL);
@@ -335,14 +336,10 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target,
        }
        return(NULL);
     }
-    ret = xmlNewDocProp(ctxt->output, cur->name, NULL);
-    if (ret == NULL) return(NULL);
-    ret->parent = target;
-    
     if (cur->ns != NULL)
-       ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target);
+       ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target);
     else
-       ret->ns = NULL;
+       ns = NULL;
 
     if (cur->children != NULL) {
        xmlChar *in = xmlNodeListGetString(ctxt->document->doc,
@@ -351,19 +348,16 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target,
 
        /* TODO: optimize if no template value was detected */
        if (in != NULL) {
-           xmlNodePtr child;
-
             out = xsltAttrTemplateValueProcess(ctxt, in);
-           child = xmlNewDocText(ctxt->output, out);
-           xmlAddChild((xmlNodePtr) ret, child);
+           ret = xmlSetNsProp(target, ns, cur->name, out);
            if (out != NULL)
                xmlFree(out);
            xmlFree(in);
        } else
-           ret->children = NULL;
+           ret = xmlSetNsProp(target, ns, cur->name, (const xmlChar *)"");
        
     } else 
-       ret->children = NULL;
+       ret = xmlSetNsProp(target, ns, cur->name, (const xmlChar *)"");
     return(ret);
 }
 
@@ -382,7 +376,7 @@ xmlAttrPtr
 xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt, 
                            xmlNodePtr target, xmlAttrPtr cur) {
     xmlAttrPtr ret = NULL;
-    xmlAttrPtr p = NULL,q;
+    xmlAttrPtr q;
     xmlNodePtr oldInsert;
 
     oldInsert = ctxt->insert;
@@ -392,12 +386,8 @@ xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt,
        if (q != NULL) {
            q->parent = target;
            q->doc = ctxt->output;
-           if (p == NULL) {
-               ret = p = q;
-           } else {
-               p->next = q;
-               q->prev = p;
-               p = q;
+           if (ret == NULL) {
+               ret = q;
            }
        }
        cur = cur->next;
index 520692c..c8b2951 100644 (file)
@@ -544,11 +544,30 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
 
                    current = ctxt->insert->properties;
                    if (current != NULL) {
-                       while (current->next != NULL)
+                       if ((xmlStrEqual(current->name, ret->name)) &&
+                           (current->ns == ret->ns)) {
+                           xmlNodePtr tmp;
+                           tmp = current->children;
+                           current->children = ret->children;
+                           ret->children = tmp;
+                           xmlFreeProp(ret);
+                           return;
+                       }
+                       while (current->next != NULL) {
                            current = current->next;
+                           if ((xmlStrEqual(current->name, ret->name)) &&
+                               (current->ns == ret->ns)) {
+                               xmlNodePtr tmp;
+                               tmp = current->children;
+                               current->children = ret->children;
+                               ret->children = tmp;
+                               xmlFreeProp(ret);
+                               return;
+                           }
+                       }
                        current->next = ret;
                        ret->prev = current;
-                   }else
+                   } else
                        ctxt->insert->properties = ret;
                }
            }
@@ -972,13 +991,6 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node,
            if (cur->properties != NULL) {
                attrs = xsltAttrListTemplateProcess(ctxt, copy,
                                                    cur->properties);
-               if (copy->properties != NULL) {
-                   xmlAttrPtr current = copy->properties;
-                   while (current->next != NULL)
-                       current = current->next;
-                   current->next = attrs;
-               } else
-                   copy->properties = attrs;
            }
        }
 
@@ -2497,7 +2509,6 @@ xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
     xsltTransformContextPtr ctxt = NULL;
     xmlNodePtr root;
     const xmlChar *method;
-    const xmlChar *encoding;
 
     if ((style == NULL) || (doc == NULL))
        return(NULL);
index e210ef3..7182c73 100644 (file)
@@ -2,7 +2,7 @@
 
 
 
-<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" font-size="12pt" font-weight="bold" quadding="start">this is the heading</fo:block>
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" quadding="start" font-size="12pt" font-weight="bold">this is the heading</fo:block>
 
 
 
index d7ac9ff..af02134 100644 (file)
@@ -30,6 +30,8 @@ EXTRA_DIST =  \
        bug-23-.xml \
        bug-24-.xml \
        bug-25-.xml \
+       bug-26-.xml \
+       bug-27-.xml \
        character.xml \
        items.xml
 
diff --git a/tests/docs/bug-27-.xml b/tests/docs/bug-27-.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
index 824047f..2dd4812 100644 (file)
@@ -30,6 +30,7 @@ EXTRA_DIST = \
     bug-24-.out bug-24-.xsl \
     bug-25-.out bug-25-.xsl \
     bug-26-.out bug-26-.xsl \
+    bug-27-.out bug-27-.xsl \
     character.out character.xsl \
     character2.out character2.xsl \
     itemschoose.out itemschoose.xsl \
diff --git a/tests/general/bug-27-.out b/tests/general/bug-27-.out
new file mode 100644 (file)
index 0000000..015b6bb
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<p attr="from-xsl-attr"/>
diff --git a/tests/general/bug-27-.xsl b/tests/general/bug-27-.xsl
new file mode 100644 (file)
index 0000000..1dedad9
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+               version="1.0">
+  <xsl:attribute-set name="my-attr-set">
+    <xsl:attribute name="attr">from-attr-set</xsl:attribute>
+  </xsl:attribute-set>
+
+  <xsl:template match="/">
+    <p xsl:use-attribute-sets="my-attr-set" attr="from-p-tag">
+      <xsl:attribute name="attr">from-xsl-attr</xsl:attribute>
+    </p>
+  </xsl:template>
+
+</xsl:stylesheet>