From: Daniel Veillard Date: Wed, 31 Jan 2001 13:27:40 +0000 (+0000) Subject: The add test/debug loop ges on: X-Git-Tag: v1.1.28~1496 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48705af02b28285cc4627e75beb8950b00423927;p=platform%2Fupstream%2Flibxslt.git The add test/debug loop ges on: - tests/REC/test-7.*: added more tests - libxslt/pattern.c libxslt/templates.c libxslt/transform.c: fixing bugs raised by said tests Daniel --- diff --git a/ChangeLog b/ChangeLog index b78c487..4853fb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jan 31 14:25:25 CET 2001 Daniel Veillard + + * tests/REC/test-7.*: added more tests + * libxslt/pattern.c libxslt/templates.c libxslt/transform.c: + fixing bugs raised by said tests + Tue Jan 30 18:55:49 CET 2001 Daniel Veillard * tests/REC/test-7.*: added more tests diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 50275d1..8d5556a 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -696,6 +696,8 @@ xsltCompileIdKeyPattern(xsltParserContextPtr ctxt, xmlChar *name, int aid) { return; } error: + if (name != NULL) + xmlFree(name); if (lit != NULL) xmlFree(lit); if (lit2 != NULL) @@ -729,6 +731,12 @@ xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) { SKIP_BLANKS; if ((token == NULL) && (CUR == '@')) { + NEXT; + if (CUR == '*') { + NEXT; + PUSH(XSLT_OP_ATTR, NULL, NULL); + return; + } token = xsltScanName(ctxt); if (token == NULL) { xsltGenericError(xsltGenericErrorContext, @@ -908,12 +916,14 @@ xsltCompileLocationPathPattern(xsltParserContextPtr ctxt) { } } else if (CUR == '*') { xsltCompileRelativePathPattern(ctxt, NULL); + } else if (CUR == '@') { + xsltCompileRelativePathPattern(ctxt, NULL); } else { xmlChar *name; name = xsltScanName(ctxt); if (name == NULL) { xsltGenericError(xsltGenericErrorContext, - "xsltCompilePattern : Name expected\n"); + "xsltCompileLocationPathPattern : Name expected\n"); ctxt->error = 1; return; } diff --git a/libxslt/templates.c b/libxslt/templates.c index 61d9f4b..8de3a95 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -266,17 +266,17 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target, xsltApplyAttributeSet(ctxt, ctxt->node, NULL, in); xmlFree(in); } - return(NULL); - } + return(NULL); } - /* TODO: check for replacement namespaces */ - ret = xmlNewDocProp(ctxt->output, cur->name, NULL); if (ret == NULL) return(NULL); ret->parent = target; - ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target); + if (cur->ns != NULL) + ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target); + else + ret->ns = NULL; if (cur->children != NULL) { xmlChar *in = xmlNodeListGetString(ctxt->doc, cur->children, 1); diff --git a/libxslt/transform.c b/libxslt/transform.c index 33c3758..23f30b4 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -125,11 +125,13 @@ xsltCopyNode(xsltTransformContextPtr ctxt, xmlNodePtr node, copy->doc = ctxt->output; if (copy != NULL) { xmlAddChild(insert, copy); - /* - * Add namespaces as they are needed - */ - if (node->nsDef != NULL) - xsltCopyNamespaceList(ctxt, copy, node->nsDef); + if (node->type == XML_ELEMENT_NODE) { + /* + * Add namespaces as they are needed + */ + if (node->nsDef != NULL) + xsltCopyNamespaceList(ctxt, copy, node->nsDef); + } if (node->ns != NULL) { copy->ns = xsltGetNamespace(ctxt, node, node->ns, copy); } @@ -362,21 +364,65 @@ void xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst) { xmlChar *prop; - xmlNodePtr copy; + xmlNodePtr copy, oldInsert; - if ((node->type != XML_DOCUMENT_NODE) && - (node->type != XML_HTML_DOCUMENT_NODE)) { - copy = xsltCopyNode(ctxt, node, ctxt->insert); - if (node->type == XML_ELEMENT_NODE) { - prop = xmlGetNsProp(inst, (const xmlChar *)"use-attribute-sets", - XSLT_NAMESPACE); - if (prop != NULL) { - TODO /* xsl:copy use-attribute-sets */ + oldInsert = ctxt->insert; + if (ctxt->insert != NULL) { + switch (node->type) { + case XML_DOCUMENT_NODE: + case XML_HTML_DOCUMENT_NODE: + break; + case XML_ELEMENT_NODE: +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsl:copy: node %s\n", node->name); +#endif + copy = xsltCopyNode(ctxt, node, ctxt->insert); + ctxt->insert = copy; + prop = xmlGetNsProp(inst, (const xmlChar *)"use-attribute-sets", + XSLT_NAMESPACE); + if (prop != NULL) { + xsltApplyAttributeSet(ctxt, node, inst, prop); + xmlFree(prop); + } + break; + case XML_ATTRIBUTE_NODE: { +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsl:copy: attribute %s\n", node->name); +#endif + if (ctxt->insert->type == XML_ELEMENT_NODE) { + xmlAttrPtr attr = (xmlAttrPtr) node, ret, cur; + if (attr->ns != NULL) { + if ((!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) && + (xmlStrncasecmp(attr->ns->prefix, + (xmlChar *)"xml", 3))) { + ret = xmlCopyProp(ctxt->insert, attr); + ret->ns = xsltGetNamespace(ctxt, node, attr->ns, + ctxt->insert); + } + } else + ret = xmlCopyProp(ctxt->insert, attr); + + cur = ctxt->insert->properties; + if (cur != NULL) { + while (cur->next != NULL) + cur = cur->next; + cur->next = ret; + ret->prev = cur; + }else + ctxt->insert->properties = ret; + } + break; } + default: + break; + } } xsltApplyOneTemplate(ctxt, ctxt->node, inst->children); + ctxt->insert = oldInsert; } /** @@ -706,6 +752,30 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { "xsltDefaultProcessOneNode: text copy failed\n"); } return; + case XML_ATTRIBUTE_NODE: + if (ctxt->insert->type == XML_ELEMENT_NODE) { + xmlAttrPtr attr = (xmlAttrPtr) node, ret, cur; + if (attr->ns != NULL) { + if ((!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) && + (xmlStrncasecmp(attr->ns->prefix, + (xmlChar *)"xml", 3))) { + ret = xmlCopyProp(ctxt->insert, attr); + ret->ns = xsltGetNamespace(ctxt, node, attr->ns, + ctxt->insert); + } + } else + ret = xmlCopyProp(ctxt->insert, attr); + + cur = ctxt->insert->properties; + if (cur != NULL) { + while (cur->next != NULL) + cur = cur->next; + cur->next = ret; + ret->prev = cur; + }else + ctxt->insert->properties = ret; + } + return; default: return; } @@ -1024,6 +1094,7 @@ error: xmlXPathFreeNodeSet(list); } + /** * xsltApplyOneTemplate: * @ctxt: a XSLT process context @@ -1415,14 +1486,34 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { xsltGenericDebug(xsltGenericDebugContext, "xsltProcessOneNode: no template found for %s\n", node->name); #endif + oldNode = ctxt->node; + ctxt->node = node; xsltDefaultProcessOneNode(ctxt, node); + ctxt->node = oldNode; return; } - oldNode = ctxt->node; - ctxt->node = node; - xsltApplyOneTemplate(ctxt, node, template->content); - ctxt->node = oldNode; + if (node->type == XML_ATTRIBUTE_NODE) { +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsltProcessOneNode: applying template for attribute %s\n", + node->name); +#endif + xsltApplyOneTemplate(ctxt, node, template->content); + } else { +#ifdef DEBUG_PROCESS + if (node->type == XML_DOCUMENT_NODE) + xsltGenericDebug(xsltGenericDebugContext, + "xsltProcessOneNode: applying template for /\n"); + else + xsltGenericDebug(xsltGenericDebugContext, + "xsltProcessOneNode: applying template for %s\n", node->name); +#endif + oldNode = ctxt->node; + ctxt->node = node; + xsltApplyOneTemplate(ctxt, node, template->content); + ctxt->node = oldNode; + } } /** diff --git a/tests/REC/test-7.3.out b/tests/REC/test-7.3.out new file mode 100644 index 0000000..923fbfa --- /dev/null +++ b/tests/REC/test-7.3.out @@ -0,0 +1,2 @@ + + diff --git a/tests/REC/test-7.3.xml b/tests/REC/test-7.3.xml new file mode 100644 index 0000000..636923c --- /dev/null +++ b/tests/REC/test-7.3.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/REC/test-7.3.xsl b/tests/REC/test-7.3.xsl new file mode 100644 index 0000000..3f699f1 --- /dev/null +++ b/tests/REC/test-7.3.xsl @@ -0,0 +1,15 @@ + + + + + + +href="book.css" type="text/css" + + + + diff --git a/tests/REC/test-7.4.out b/tests/REC/test-7.4.out new file mode 100644 index 0000000..cf037f2 --- /dev/null +++ b/tests/REC/test-7.4.out @@ -0,0 +1,2 @@ + + diff --git a/tests/REC/test-7.4.xml b/tests/REC/test-7.4.xml new file mode 100644 index 0000000..636923c --- /dev/null +++ b/tests/REC/test-7.4.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/REC/test-7.4.xsl b/tests/REC/test-7.4.xsl new file mode 100644 index 0000000..8059473 --- /dev/null +++ b/tests/REC/test-7.4.xsl @@ -0,0 +1,15 @@ + + + + + + +This file is automatically generated. Do not edit! + + + + diff --git a/tests/REC/test-7.5-1.out b/tests/REC/test-7.5-1.out new file mode 100644 index 0000000..450c3f1 --- /dev/null +++ b/tests/REC/test-7.5-1.out @@ -0,0 +1,4 @@ + + + content + diff --git a/tests/REC/test-7.5-1.xml b/tests/REC/test-7.5-1.xml new file mode 100644 index 0000000..f3a0c0a --- /dev/null +++ b/tests/REC/test-7.5-1.xml @@ -0,0 +1,3 @@ + + content + diff --git a/tests/REC/test-7.5-1.xsl b/tests/REC/test-7.5-1.xsl new file mode 100644 index 0000000..b832f5f --- /dev/null +++ b/tests/REC/test-7.5-1.xsl @@ -0,0 +1,12 @@ + + + + + + + +