From 50f6648ff3def6e01581209a0319a47e785aa9f9 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 30 Apr 2001 20:34:11 +0000 Subject: [PATCH] - tests/general/bug-8-.out: fixed in libxml xpath - libxslt/templates.[ch] libxslt/pattern.c: fixed an namespace problem in predicates within a pattern. Spotted another potential namespace problem Daniel --- ChangeLog | 7 +++++++ libxslt/pattern.c | 19 ++++++++++++++++++- libxslt/templates.c | 11 ++++++----- libxslt/templates.h | 7 ++++++- tests/general/bug-8-.out | 2 +- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb4bed5..b161a53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Apr 30 22:31:59 CEST 2001 Daniel Veillard + + * tests/general/bug-8-.out: fixed in libxml xpath + * libxslt/templates.[ch] libxslt/pattern.c: fixed an namespace + problem in predicates within a pattern. Spotted another + potential namespace problem + Mon Apr 30 19:29:34 CEST 2001 Daniel Veillard * libxslt/preproc.c libxslt/xslt.c libxslt/xsltInternals.h diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 5eaba15..94fe45c 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -86,6 +86,8 @@ struct _xsltCompMatch { /* TODO fix the statically allocated size steps[] */ int nbStep; int maxStep; + xmlNsPtr *nsList; /* the namespaces in scope */ + int nsNr; /* the number of namespaces in scope */ xsltStepOp steps[20]; /* ops for computation */ }; @@ -125,6 +127,8 @@ xsltNewCompMatch(void) { } memset(cur, 0, sizeof(xsltCompMatch)); cur->maxStep = 20; + cur->nsNr = 0; + cur->nsList = NULL; return(cur); } @@ -145,6 +149,8 @@ xsltFreeCompMatch(xsltCompMatchPtr comp) { xmlFree((xmlChar *)comp->mode); if (comp->modeURI != NULL) xmlFree((xmlChar *)comp->modeURI); + if (comp->nsList != NULL) + xmlFree(comp->nsList); for (i = 0;i < comp->nbStep;i++) { op = &comp->steps[i]; if (op->value != NULL) @@ -668,7 +674,18 @@ xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp, if (step->comp == NULL) goto wrong_index; } - if (!xsltEvalXPathPredicate(ctxt, step->comp)) + if (comp->nsList == NULL) { + int j = 0; + + comp->nsList = xmlGetNsList(node->doc, node); + if (comp->nsList != NULL) { + while (comp->nsList[j] != NULL) + j++; + } + comp->nsNr = j; + } + if (!xsltEvalXPathPredicate(ctxt, step->comp, comp->nsList, + comp->nsNr)) goto wrong_index; if (pos != 0) { diff --git a/libxslt/templates.c b/libxslt/templates.c index ea9aa2d..9299436 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -42,6 +42,8 @@ * xsltEvalXPathPredicate: * @ctxt: the XSLT transformation context * @comp: the XPath compiled expression + * @nsList: the namespaces in scope + * @int nsNr: the number of namespaces in scope * * Process the expression using XPath and evaluate the result as * an XPath predicate @@ -49,16 +51,15 @@ * Returns 1 is the predicate was true, 0 otherwise */ int -xsltEvalXPathPredicate(xsltTransformContextPtr ctxt, - xmlXPathCompExprPtr comp) { +xsltEvalXPathPredicate(xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp, + xmlNsPtr *nsList, int nsNr) { int ret, position; xmlXPathObjectPtr res; position = ctxt->xpathCtxt->proximityPosition; ctxt->xpathCtxt->node = ctxt->node; - /* TODO: do we need to propagate the namespaces here ? */ - ctxt->xpathCtxt->namespaces = NULL; - ctxt->xpathCtxt->nsNr = 0; + ctxt->xpathCtxt->namespaces = nsList; + ctxt->xpathCtxt->nsNr = nsNr; res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt); ctxt->xpathCtxt->proximityPosition = position; if (res != NULL) { diff --git a/libxslt/templates.h b/libxslt/templates.h index 02637c5..847e6da 100644 --- a/libxslt/templates.h +++ b/libxslt/templates.h @@ -18,7 +18,9 @@ extern "C" { #endif int xsltEvalXPathPredicate (xsltTransformContextPtr ctxt, - xmlXPathCompExprPtr comp); + xmlXPathCompExprPtr comp, + xmlNsPtr *nsList, + int nsNr); xmlChar * xsltEvalTemplateString (xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr parent); @@ -31,8 +33,11 @@ xmlChar * xsltEvalStaticAttrValueTemplate (xsltStylesheetPtr style, const xmlChar *name, const xmlChar *ns, int *found); + +/* TODO: this is obviously broken ... the namespaces should be passed too ! */ xmlChar * xsltEvalXPathString (xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp); + xmlNodePtr * xsltTemplateProcess (xsltTransformContextPtr ctxt, xmlNodePtr node); xmlAttrPtr xsltAttrListTemplateProcess (xsltTransformContextPtr ctxt, diff --git a/tests/general/bug-8-.out b/tests/general/bug-8-.out index 9f6689b..cdf2066 100644 --- a/tests/general/bug-8-.out +++ b/tests/general/bug-8-.out @@ -1,3 +1,3 @@ - Big + Big Success -- 2.7.4