From a7c43a4198c1f10fc0ce2949a14bed07a67de12b Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 11 May 2001 17:15:46 +0000 Subject: [PATCH] - 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 Daniel --- ChangeLog | 9 +++++++++ libxslt/templates.c | 28 +++++++++------------------- libxslt/transform.c | 31 +++++++++++++++++++++---------- tests/REC/test-7.1.4.out | 2 +- tests/docs/Makefile.am | 2 ++ tests/docs/bug-27-.xml | 1 + tests/general/Makefile.am | 1 + tests/general/bug-27-.out | 2 ++ tests/general/bug-27-.xsl | 14 ++++++++++++++ 9 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 tests/docs/bug-27-.xml create mode 100644 tests/general/bug-27-.out create mode 100644 tests/general/bug-27-.xsl diff --git a/ChangeLog b/ChangeLog index 4592ec6..e9c2304 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri May 11 19:12:26 CEST 2001 Daniel Veillard + + * 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 * libxslt/templates.c: fixed bug #54451 on escaped curly brackets diff --git a/libxslt/templates.c b/libxslt/templates.c index 089dad4..7ce01be 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -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; diff --git a/libxslt/transform.c b/libxslt/transform.c index 520692c..c8b2951 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -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); diff --git a/tests/REC/test-7.1.4.out b/tests/REC/test-7.1.4.out index e210ef3..7182c73 100644 --- a/tests/REC/test-7.1.4.out +++ b/tests/REC/test-7.1.4.out @@ -2,7 +2,7 @@ -this is the heading +this is the heading diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am index d7ac9ff..af02134 100644 --- a/tests/docs/Makefile.am +++ b/tests/docs/Makefile.am @@ -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 index 0000000..69d62f2 --- /dev/null +++ b/tests/docs/bug-27-.xml @@ -0,0 +1 @@ + diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am index 824047f..2dd4812 100644 --- a/tests/general/Makefile.am +++ b/tests/general/Makefile.am @@ -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 index 0000000..015b6bb --- /dev/null +++ b/tests/general/bug-27-.out @@ -0,0 +1,2 @@ + +

diff --git a/tests/general/bug-27-.xsl b/tests/general/bug-27-.xsl new file mode 100644 index 0000000..1dedad9 --- /dev/null +++ b/tests/general/bug-27-.xsl @@ -0,0 +1,14 @@ + + + + from-attr-set + + + +

+ from-xsl-attr +

+ + + -- 2.7.4