From f73f508250edd0816c9f233c20a77a6511f6064e Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 10 Sep 2001 17:43:00 +0000 Subject: [PATCH] fixed bug #59757 on inheritance of attributes from multiple * libxslt/attributes.c libxslt/transform.c: fixed bug #59757 on inheritance of attributes from multiple attributes-sets Daniel --- ChangeLog | 5 ++ libxslt/attributes.c | 143 ++++++++++++++++++++++++++++++++++++++++++- libxslt/transform.c | 117 ----------------------------------- 3 files changed, 146 insertions(+), 119 deletions(-) diff --git a/ChangeLog b/ChangeLog index c20b98df..1cb76ed0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Sep 10 19:38:54 CEST 2001 Daniel Veillard + + * libxslt/attributes.c libxslt/transform.c: fixed bug #59757 + on inheritance of attributes from multiple attributes-sets + Mon Sep 3 02:14:58 CEST 2001 Thomas Broyer * libexslt/Makefile.am libexslt/exslt.[ch] libexslt/strings.c: diff --git a/libxslt/attributes.c b/libxslt/attributes.c index c2ade9d4..249efa15 100644 --- a/libxslt/attributes.c +++ b/libxslt/attributes.c @@ -368,6 +368,145 @@ error: xmlFree(prefix); } +/** + * xsltAttributeInternal: + * @ctxt: a XSLT process context + * @node: the node in the source tree. + * @inst: the xslt attribute node + * @comp: precomputed information + * @fromset: the attribute comes from an attribute-set + * + * Process the xslt attribute node on the source node + */ +static void +xsltAttributeInternal(xsltTransformContextPtr ctxt, xmlNodePtr node, + xmlNodePtr inst, xsltStylePreCompPtr comp, int fromset) { + xmlChar *prop = NULL; + xmlChar *ncname = NULL, *name, *namespace; + xmlChar *prefix = NULL; + xmlChar *value = NULL; + xmlNsPtr ns = NULL; + xmlAttrPtr attr; + const xmlChar *URL = NULL; + + + if (ctxt->insert == NULL) + return; + if (comp == NULL) { + xsltPrintErrorContext(ctxt, NULL, inst); + xsltGenericError(xsltGenericErrorContext, + "xsl:attribute : compilation failed\n"); + return; + } + + if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL)) + return; + if (!comp->has_name) { + return; + } + if (ctxt->insert->children != NULL) { + xsltPrintErrorContext(ctxt, NULL, inst); + xsltGenericError(xsltGenericErrorContext, + "xsl:attribute : node already has children\n"); + return; + } + if (comp->name == NULL) { + prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *)"name", + XSLT_NAMESPACE); + if (prop == NULL) { + xsltPrintErrorContext(ctxt, NULL, inst); + xsltGenericError(xsltGenericErrorContext, + "xsl:attribute : name is missing\n"); + goto error; + } + name = prop; + } else { + name = comp->name; + } + + ncname = xmlSplitQName2(name, &prefix); + if (ncname == NULL) { + prefix = NULL; + } else { + name = ncname; + } + if (!xmlStrncasecmp(prefix, (xmlChar *)"xml", 3)) { +#ifdef WITH_XSLT_DEBUG_PARSING + xsltGenericDebug(xsltGenericDebugContext, + "xsltAttribute: xml prefix forbidden\n"); +#endif + goto error; + } + if ((comp->ns == NULL) && (comp->has_ns)) { + namespace = xsltEvalAttrValueTemplate(ctxt, inst, + (const xmlChar *)"namespace", XSLT_NAMESPACE); + if (namespace != NULL) { + ns = xsltGetSpecialNamespace(ctxt, inst, namespace, prefix, + ctxt->insert); + xmlFree(namespace); + } else { + if (prefix != NULL) { + ns = xmlSearchNs(inst->doc, inst, prefix); + if (ns == NULL) { + xsltPrintErrorContext(ctxt, NULL, inst); + xsltGenericError(xsltGenericErrorContext, + "xsl:attribute : no namespace bound to prefix %s\n", prefix); + } else { + ns = xsltGetNamespace(ctxt, inst, ns, ctxt->insert); + } + } + } + } else if (comp->ns != NULL) { + ns = xsltGetSpecialNamespace(ctxt, inst, comp->ns, prefix, + ctxt->insert); + } + + if ((fromset) && (ns != NULL)) + URL = ns->href; + if ((fromset == 0) || (!xmlHasNsProp(ctxt->insert, name, URL))) { + value = xsltEvalTemplateString(ctxt, node, inst); + if (value == NULL) { + if (ns) { + attr = xmlSetNsProp(ctxt->insert, ns, name, + (const xmlChar *)""); + } else { + attr = xmlSetProp(ctxt->insert, name, (const xmlChar *)""); + } + } else { + if (ns) { + attr = xmlSetNsProp(ctxt->insert, ns, name, value); + } else { + attr = xmlSetProp(ctxt->insert, name, value); + } + } + } + +error: + if (prop != NULL) + xmlFree(prop); + if (ncname != NULL) + xmlFree(ncname); + if (prefix != NULL) + xmlFree(prefix); + if (value != NULL) + xmlFree(value); +} + +/** + * xsltAttribute: + * @ctxt: a XSLT process context + * @node: the node in the source tree. + * @inst: the xslt attribute node + * @comp: precomputed information + * + * Process the xslt attribute node on the source node + */ +void +xsltAttribute(xsltTransformContextPtr ctxt, xmlNodePtr node, + xmlNodePtr inst, xsltStylePreCompPtr comp) { + xsltAttributeInternal(ctxt, node, inst, comp, 0); +} + /** * xsltApplyAttributeSet: * @ctxt: the XSLT stylesheet @@ -416,8 +555,8 @@ xsltApplyAttributeSet(xsltTransformContextPtr ctxt, xmlNodePtr node, values = xmlHashLookup2(style->attributeSets, ncname, prefix); while (values != NULL) { if (values->attr != NULL) { - xsltAttribute(ctxt, node, values->attr, - values->attr->_private); + xsltAttributeInternal(ctxt, node, values->attr, + values->attr->_private, 1); } values = values->next; } diff --git a/libxslt/transform.c b/libxslt/transform.c index 23b4c386..40f2f946 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -1988,123 +1988,6 @@ error: xmlFree(value); } -/** - * xsltAttribute: - * @ctxt: a XSLT process context - * @node: the node in the source tree. - * @inst: the xslt attribute node - * @comp: precomputed information - * - * Process the xslt attribute node on the source node - */ -void -xsltAttribute(xsltTransformContextPtr ctxt, xmlNodePtr node, - xmlNodePtr inst, xsltStylePreCompPtr comp) { - xmlChar *prop = NULL; - xmlChar *ncname = NULL, *name, *namespace; - xmlChar *prefix = NULL; - xmlChar *value = NULL; - xmlNsPtr ns = NULL; - xmlAttrPtr attr; - - - if (ctxt->insert == NULL) - return; - if (comp == NULL) { - xsltPrintErrorContext(ctxt, NULL, inst); - xsltGenericError(xsltGenericErrorContext, - "xsl:attribute : compilation failed\n"); - return; - } - - if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL)) - return; - if (!comp->has_name) { - return; - } - if (ctxt->insert->children != NULL) { - xsltPrintErrorContext(ctxt, NULL, inst); - xsltGenericError(xsltGenericErrorContext, - "xsl:attribute : node already has children\n"); - return; - } - if (comp->name == NULL) { - prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *)"name", - XSLT_NAMESPACE); - if (prop == NULL) { - xsltPrintErrorContext(ctxt, NULL, inst); - xsltGenericError(xsltGenericErrorContext, - "xsl:attribute : name is missing\n"); - goto error; - } - name = prop; - } else { - name = comp->name; - } - - ncname = xmlSplitQName2(name, &prefix); - if (ncname == NULL) { - prefix = NULL; - } else { - name = ncname; - } - if (!xmlStrncasecmp(prefix, (xmlChar *)"xml", 3)) { -#ifdef WITH_XSLT_DEBUG_PARSING - xsltGenericDebug(xsltGenericDebugContext, - "xsltAttribute: xml prefix forbidden\n"); -#endif - goto error; - } - if ((comp->ns == NULL) && (comp->has_ns)) { - namespace = xsltEvalAttrValueTemplate(ctxt, inst, - (const xmlChar *)"namespace", XSLT_NAMESPACE); - if (namespace != NULL) { - ns = xsltGetSpecialNamespace(ctxt, inst, namespace, prefix, - ctxt->insert); - xmlFree(namespace); - } else { - if (prefix != NULL) { - ns = xmlSearchNs(inst->doc, inst, prefix); - if (ns == NULL) { - xsltPrintErrorContext(ctxt, NULL, inst); - xsltGenericError(xsltGenericErrorContext, - "xsl:attribute : no namespace bound to prefix %s\n", prefix); - } else { - ns = xsltGetNamespace(ctxt, inst, ns, ctxt->insert); - } - } - } - } else if (comp->ns != NULL) { - ns = xsltGetSpecialNamespace(ctxt, inst, comp->ns, prefix, - ctxt->insert); - } - - value = xsltEvalTemplateString(ctxt, node, inst); - if (value == NULL) { - if (ns) { - attr = xmlSetNsProp(ctxt->insert, ns, name, - (const xmlChar *)""); - } else - attr = xmlSetProp(ctxt->insert, name, (const xmlChar *)""); - } else { - if (ns) { - attr = xmlSetNsProp(ctxt->insert, ns, name, value); - } else - attr = xmlSetProp(ctxt->insert, name, value); - - } - -error: - if (prop != NULL) - xmlFree(prop); - if (ncname != NULL) - xmlFree(ncname); - if (prefix != NULL) - xmlFree(prefix); - if (value != NULL) - xmlFree(value); -} - /** * xsltComment: