From b0cd3047a8789122ffa099e138a927ebd26e5974 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 11 Feb 2002 12:29:06 +0000 Subject: [PATCH] expected to have closed bug #70131, still wondering about the position() * libxslt/xsltInternals.h libxslt/pattern.c: expected to have closed bug #70131, still wondering about the position() when the node is selected. Daniel --- ChangeLog | 6 ++++++ libxslt/pattern.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ libxslt/xsltInternals.h | 1 + 3 files changed, 59 insertions(+) diff --git a/ChangeLog b/ChangeLog index 45ab616..8cb23d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Feb 11 13:27:42 CET 2002 Daniel Veillard + + * libxslt/xsltInternals.h libxslt/pattern.c: expected to have + closed bug #70131, still wondering about the position() when + the node is selected. + Mon Feb 11 10:45:27 CET 2002 Daniel Veillard * tests/docs/Makefile.am tests/docs/bug-71.xml diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 36b1ada..7b8ad80 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -561,6 +561,58 @@ xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp, int oldCS, oldCP; int pos = 0, len = 0; /* + * The simple existing predicate code cannot handle + * properly cascaded predicates. If in this situation + * compute directly the full node list once and check + * if the node is in the result list. + */ + if (comp->steps[i + 1].op == XSLT_OP_PREDICATE) { + xmlNodePtr previous; + xmlXPathObjectPtr list; + int index, j; + + previous = (xmlNodePtr) + XSLT_RUNTIME_EXTRA(ctxt, select->previousExtra); + index = (int) + XSLT_RUNTIME_EXTRA(ctxt, select->indexExtra); + list = (xmlXPathObjectPtr) + XSLT_RUNTIME_EXTRA(ctxt, select->lenExtra); + if (list == NULL) { + xmlChar *query; + + if (comp->pattern[0] == '/') + query = xmlStrdup(comp->pattern); + else { + query = xmlStrdup((const xmlChar *)"//"); + query = xmlStrcat(query, comp->pattern); + } + list = xmlXPathEval(query, ctxt->xpathCtxt); + xmlFree(query); + if (list == NULL) + return(-1); + if (list->type != XPATH_NODESET) { + xmlXPathFreeObject(list); + return(-1); + } + XSLT_RUNTIME_EXTRA(ctxt, select->lenExtra) = + (void *) list; + XSLT_RUNTIME_EXTRA_FREE(ctxt, select->lenExtra) = + (xmlFreeFunc) xmlXPathFreeObject; + } + if ((list->nodesetval == NULL) || + (list->nodesetval->nodeNr <= 0)) + return(0); + if (index == 0) { + for (j = 0;j < list->nodesetval->nodeNr;j++) { + if (list->nodesetval->nodeTab[j] == node) { + return(1); + } + } + } else { + } + return(0); + } + /* * Depending on the last selection, one may need to * recompute contextSize and proximityPosition. * diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index bbb8554..878b4f3 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -49,6 +49,7 @@ struct _xsltRuntimeExtra { }; #define XSLT_RUNTIME_EXTRA(ctxt, nr) (ctxt)->extras[(nr)].info +#define XSLT_RUNTIME_EXTRA_FREE(ctxt, nr) (ctxt)->extras[(nr)].deallocate /** * xsltTemplate: -- 2.7.4