From: Daniel Veillard Date: Tue, 30 Jan 2001 18:00:24 +0000 (+0000) Subject: Testing/debugging: - tests/REC/test-7.*: added more tests - X-Git-Tag: v1.1.28~1497 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=598bfacb27515e22557c61a295fd63225e6dbdc1;p=platform%2Fupstream%2Flibxslt.git Testing/debugging: - tests/REC/test-7.*: added more tests - Testing/debugging: - tests/REC/test-7.*: added more tests - libxslt/namespaces.[ch] libxslt/pattern.c libxslt/attributes.c libxslt/templates.c libxslt/transform.c libxslt/xslt.c: fixing bugs raised by said tests Daniel --- diff --git a/ChangeLog b/ChangeLog index a66f0fd..b78c487 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Jan 30 18:55:49 CET 2001 Daniel Veillard + + * tests/REC/test-7.*: added more tests + * libxslt/namespaces.[ch] libxslt/pattern.c libxslt/attributes.c + libxslt/templates.c libxslt/transform.c libxslt/xslt.c: fixing bugs + raised by said tests + Tue Jan 30 15:16:56 CET 2001 Daniel Veillard * TODO: updated diff --git a/libxslt/attributes.c b/libxslt/attributes.c index 3bafd1c..ac54dcb 100644 --- a/libxslt/attributes.c +++ b/libxslt/attributes.c @@ -207,23 +207,23 @@ xsltParseStylesheetAttributeSet(xsltStylesheetPtr style, xmlNodePtr cur) { list = cur->children; delete = NULL; while (list != NULL) { - if (IS_XSLT_ELEM(cur)) { - if (!IS_XSLT_NAME(cur, "attribute")) { + if (IS_XSLT_ELEM(list)) { + if (!IS_XSLT_NAME(list, "attribute")) { xsltGenericError(xsltGenericErrorContext, "xslt:attribute-set : unexpected child xsl:%s\n", - cur->name); - delete = cur; + list->name); + delete = list; } else { #ifdef DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "add attribute to list %s\n", ncname); #endif - values = xsltAddAttrElemList(values, cur); + values = xsltAddAttrElemList(values, list); } } else { xsltGenericError(xsltGenericErrorContext, - "xslt:attribute-set : unexpected child %s\n", cur->name); - delete = cur; + "xslt:attribute-set : unexpected child %s\n", list->name); + delete = list; } list = list->next; } @@ -316,16 +316,16 @@ xsltAttribute(xsltTransformContextPtr ctxt, xmlNodePtr node, prop = NULL; prefix = NULL; } - if (xmlStrEqual(ncname, (const xmlChar *) "xmlns")) { - xsltGenericError(xsltGenericErrorContext, - "xslt:attribute : xmlns forbidden\n"); + if ((prefix != NULL) && (xmlStrEqual(prefix, (const xmlChar *)"xmlns"))) { +#ifdef DEBUG_PARSING + xsltGenericDebug(xsltGenericDebugContext, + "xslt:attribute : xmlns prefix forbidden\n"); +#endif goto error; } prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *)"namespace"); if (prop != NULL) { TODO /* xsl:attribute namespace */ - xmlFree(prop); - return; } else { if (prefix != NULL) { ns = xmlSearchNs(inst->doc, inst, prefix); diff --git a/libxslt/namespaces.c b/libxslt/namespaces.c index 9842453..384836d 100644 --- a/libxslt/namespaces.c +++ b/libxslt/namespaces.c @@ -139,11 +139,6 @@ xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, if ((ctxt == NULL) || (cur == NULL) || (out == NULL) || (ns == NULL)) return(NULL); - if ((out->type == XML_ELEMENT_NODE) && (out->ns != NULL) && - ((out->ns->href != NULL) && (ns->href != NULL) && - (xmlStrEqual(out->ns->href, ns->href)))) { - return(out->ns); - } /* TODO apply cascading */ if (ctxt->style->nsAliases != NULL) { @@ -153,10 +148,17 @@ xsltGetNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, xmlNsPtr ns, } else URI = ns->href; - ret = xmlSearchNsByHref(out->doc, out, URI); + if ((out->parent != NULL) && + (out->parent->type == XML_ELEMENT_NODE) && + (out->parent->ns != NULL) && + (xmlStrEqual(out->parent->ns->href, URI))) + ret = out->parent->ns; + else + ret = xmlSearchNsByHref(out->doc, out, URI); + if (ret == NULL) { if (out->type == XML_ELEMENT_NODE) - ret = xmlNewNs(out, ns->href, ns->prefix); + ret = xmlNewNs(out, URI, ns->prefix); } return(ret); } @@ -202,3 +204,16 @@ xsltCopyNamespaceList(xsltTransformContextPtr ctxt, xmlNodePtr node, return(ret); } + +/** + * xsltFreeNamespaceAliasHashes: + * @style: an XSLT stylesheet + * + * Free up the memory used by namespaces aliases + */ +void +xsltFreeNamespaceAliasHashes(xsltStylesheetPtr style) { + if (style->nsAliases != NULL) + xmlHashFree((xmlHashTablePtr) style->nsAliases, NULL); + style->nsAliases = NULL; +} diff --git a/libxslt/namespaces.h b/libxslt/namespaces.h index 14c2f4d..a4158a8 100644 --- a/libxslt/namespaces.h +++ b/libxslt/namespaces.h @@ -24,6 +24,7 @@ xmlNsPtr xsltGetNamespace (xsltTransformContextPtr ctxt, xmlNsPtr xsltCopyNamespaceList (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNsPtr cur); +void xsltFreeNamespaceAliasHashes(xsltStylesheetPtr style); #ifdef __cplusplus } #endif diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 2c4129c..50275d1 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -1263,7 +1263,7 @@ xsltGetTemplate(xsltStylesheetPtr style, xmlNodePtr node) { case XML_NAMESPACE_DECL: case XML_XINCLUDE_START: case XML_XINCLUDE_END: - return(NULL); + break; default: return(NULL); diff --git a/libxslt/templates.c b/libxslt/templates.c index 66d6e40..61d9f4b 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -26,6 +26,7 @@ #include "templates.h" #include "transform.h" #include "namespaces.h" +#include "attributes.h" #define DEBUG_TEMPLATES @@ -257,9 +258,19 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target, if ((cur->ns != NULL) && (xmlStrEqual(cur->ns->href, XSLT_NAMESPACE))) { - /* TODO: check for replacement namespaces */ - return(NULL); + if (xmlStrEqual(cur->name, (const xmlChar *)"use-attribute-sets")) { + xmlChar *in; + + in = xmlNodeListGetString(ctxt->doc, cur->children, 1); + if (in != NULL) { + xsltApplyAttributeSet(ctxt, ctxt->node, NULL, in); + xmlFree(in); + } + return(NULL); + + } } + /* TODO: check for replacement namespaces */ ret = xmlNewDocProp(ctxt->output, cur->name, NULL); if (ret == NULL) return(NULL); @@ -304,7 +315,10 @@ xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target, xmlAttrPtr cur) { xmlAttrPtr ret = NULL; xmlAttrPtr p = NULL,q; + xmlNodePtr oldInsert; + oldInsert = ctxt->insert; + ctxt->insert = target; while (cur != NULL) { q = xsltAttrTemplateProcess(ctxt, target, cur); if (q != NULL) { @@ -320,6 +334,7 @@ xsltAttrListTemplateProcess(xsltTransformContextPtr ctxt, } cur = cur->next; } + ctxt->insert = oldInsert; return(ret); } diff --git a/libxslt/transform.c b/libxslt/transform.c index 96e1884..33c3758 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -31,6 +31,7 @@ #include "transform.h" #include "variables.h" #include "namespaces.h" +#include "attributes.h" #include "templates.h" #define DEBUG_PROCESS @@ -1036,6 +1037,7 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr list) { xmlNodePtr cur = NULL, insert, copy = NULL; xmlNodePtr oldInsert; + xmlAttrPtr attrs; int has_variables = 0; CHECK_STOPPED; @@ -1153,11 +1155,18 @@ xsltApplyOneTemplate(xsltTransformContextPtr ctxt, xmlNodePtr node, copy = xsltCopyNode(ctxt, cur, insert); /* * all the attributes are directly inherited - * TODO: Do the substitution of {} XPath expressions !!! */ - if (cur->properties != NULL) - copy->properties = xsltAttrListTemplateProcess(ctxt, - copy, cur->properties); + if (cur->properties != NULL) { + attrs = xsltAttrListTemplateProcess(ctxt, copy, + cur->properties); + if (copy->properties != NULL) { + xmlAttrPtr cur = copy->properties; + while (cur->next != NULL) + cur = cur->next; + cur->next = attrs; + } else + copy->properties = attrs; + } } /* @@ -1391,6 +1400,7 @@ error: void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { xsltTemplatePtr template; + xmlNodePtr oldNode; template = xsltGetTemplate(ctxt->style, node); /* @@ -1409,7 +1419,10 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { return; } + oldNode = ctxt->node; + ctxt->node = node; xsltApplyOneTemplate(ctxt, node, template->content); + ctxt->node = oldNode; } /** diff --git a/libxslt/xslt.c b/libxslt/xslt.c index c75ace4..3154d8d 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -264,6 +264,7 @@ xsltFreeStylesheet(xsltStylesheetPtr sheet) { xsltFreeDecimalFormatList(sheet); xsltFreeTemplateList(sheet->templates); xsltFreeAttributeSetsHashes(sheet); + xsltFreeNamespaceAliasHashes(sheet); if (sheet->doc != NULL) xmlFreeDoc(sheet->doc); if (sheet->variables != NULL) diff --git a/tests/REC/test-7.1.1.out b/tests/REC/test-7.1.1.out new file mode 100644 index 0000000..f21cf90 --- /dev/null +++ b/tests/REC/test-7.1.1.out @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/REC/test-7.1.1.xml b/tests/REC/test-7.1.1.xml new file mode 100644 index 0000000..d88b575 --- /dev/null +++ b/tests/REC/test-7.1.1.xml @@ -0,0 +1,7 @@ + +p +h1 +h2 +h3 +h4 + diff --git a/tests/REC/test-7.1.1.xsl b/tests/REC/test-7.1.1.xsl new file mode 100644 index 0000000..10cc935 --- /dev/null +++ b/tests/REC/test-7.1.1.xsl @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/REC/test-7.1.3.out b/tests/REC/test-7.1.3.out new file mode 100644 index 0000000..dee0832 --- /dev/null +++ b/tests/REC/test-7.1.3.out @@ -0,0 +1,2 @@ + + diff --git a/tests/REC/test-7.1.3.xml b/tests/REC/test-7.1.3.xml new file mode 100644 index 0000000..69d62f2 --- /dev/null +++ b/tests/REC/test-7.1.3.xml @@ -0,0 +1 @@ + diff --git a/tests/REC/test-7.1.3.xsl b/tests/REC/test-7.1.3.xsl new file mode 100644 index 0000000..e54f6f3 --- /dev/null +++ b/tests/REC/test-7.1.3.xsl @@ -0,0 +1,20 @@ + + + + + + +http://www.w3.org/1999/XSL/Transform +value + + + + + diff --git a/tests/REC/test-7.1.4.out b/tests/REC/test-7.1.4.out new file mode 100644 index 0000000..e210ef3 --- /dev/null +++ b/tests/REC/test-7.1.4.out @@ -0,0 +1,8 @@ + + + + +this is the heading + + + diff --git a/tests/REC/test-7.1.4.xml b/tests/REC/test-7.1.4.xml new file mode 100644 index 0000000..50ab16a --- /dev/null +++ b/tests/REC/test-7.1.4.xml @@ -0,0 +1,5 @@ + + +this is the heading + + diff --git a/tests/REC/test-7.1.4.xsl b/tests/REC/test-7.1.4.xsl new file mode 100644 index 0000000..88c61b9 --- /dev/null +++ b/tests/REC/test-7.1.4.xsl @@ -0,0 +1,19 @@ + + + + + + + + + + + + 12pt + bold + +