From 145c37ba026a8216b239ef7ef2cadda5ef83ec97 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 24 Mar 2003 14:04:00 +0000 Subject: [PATCH] Finally fixed bug #75813, processing or Result Value Tree converted into * libxslt/pattern.c libxslt/transform.c libxslt/variables.c: Finally fixed bug #75813, processing or Result Value Tree converted into node-sets should be a bit more sensible now. * tests/exslt/common/node-set.2.out: the associated fix in libxml2 fixes this regression test, there is 4 nodes, not 3 * tests/docs/Makefile.am tests/docs/bug-111.* tests/general/Makefile.am tests/general/bug-111*: added an example in the regression tests for bug #75813 Daniel --- ChangeLog | 11 ++++++++++ libxslt/pattern.c | 8 +++++++ libxslt/transform.c | 31 +++++++++++++++++---------- libxslt/variables.c | 10 +++++---- tests/docs/Makefile.am | 1 + tests/docs/bug-111.xml | 17 +++++++++++++++ tests/exslt/common/node-set.2.out | 2 +- tests/general/Makefile.am | 1 + tests/general/bug-111.out | 6 ++++++ tests/general/bug-111.xsl | 45 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 tests/docs/bug-111.xml create mode 100644 tests/general/bug-111.out create mode 100644 tests/general/bug-111.xsl diff --git a/ChangeLog b/ChangeLog index 377c9f6..921dcdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Mon Mar 24 15:01:07 CET 2003 Daniel Veillard + + * libxslt/pattern.c libxslt/transform.c libxslt/variables.c: + Finally fixed bug #75813, processing or Result Value Tree + converted into node-sets should be a bit more sensible now. + * tests/exslt/common/node-set.2.out: the associated fix in libxml2 + fixes this regression test, there is 4 nodes, not 3 + * tests/docs/Makefile.am tests/docs/bug-111.* + tests/general/Makefile.am tests/general/bug-111*: added an + example in the regression tests for bug #75813 + Sun Mar 23 13:09:17 CET 2003 Daniel Veillard * tests/docs/Makefile.am tests/docs/bug-110.* diff --git a/libxslt/pattern.c b/libxslt/pattern.c index dc2ed01..53ae86c 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -611,6 +611,8 @@ xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp, xmlChar *query; xmlXPathObjectPtr newlist; xmlNodePtr parent = node->parent; + xmlDocPtr olddoc; + xmlNodePtr oldnode; if (comp->pattern[0] == '/') query = xmlStrdup(comp->pattern); @@ -618,7 +620,13 @@ xsltTestCompMatch(xsltTransformContextPtr ctxt, xsltCompMatchPtr comp, query = xmlStrdup((const xmlChar *)"//"); query = xmlStrcat(query, comp->pattern); } + oldnode = ctxt->xpathCtxt->node; + olddoc = ctxt->xpathCtxt->doc; + ctxt->xpathCtxt->node = node; + ctxt->xpathCtxt->doc = doc; newlist = xmlXPathEval(query, ctxt->xpathCtxt); + ctxt->xpathCtxt->node = oldnode; + ctxt->xpathCtxt->doc = olddoc; xmlFree(query); if (newlist == NULL) return(-1); diff --git a/libxslt/transform.c b/libxslt/transform.c index 9c6e40d..6901657 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -3064,18 +3064,27 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node, (list->nodeTab[i]->doc->doc)!=ctxt->xpathCtxt->doc) { /* The nodeset is from another document, so must change */ ctxt->xpathCtxt->doc=list->nodeTab[i]->doc->doc; - if ((ctxt->document = - xsltFindDocument(ctxt,list->nodeTab[i]->doc->doc))==NULL) { - xsltTransformError(ctxt, NULL, inst, - "xsl:apply-templates : can't find doc\n"); - goto error; - } - ctxt->xpathCtxt->node = list->nodeTab[i]; + if (list->nodeTab[i]->doc->type != XML_ELEMENT_NODE) { + if ((ctxt->document = xsltFindDocument(ctxt, + list->nodeTab[i]->doc->doc))==NULL) { + xsltTransformError(ctxt, NULL, inst, + "xsl:apply-templates : can't find doc\n"); + goto error; + } + ctxt->xpathCtxt->node = list->nodeTab[i]; #ifdef WITH_XSLT_DEBUG_PROCESS - xsltGenericDebug(xsltGenericDebugContext, - "xsltApplyTemplates: Changing document - context doc %s, xpathdoc %s\n", - ctxt->document->doc->URL, ctxt->xpathCtxt->doc->URL); + xsltGenericDebug(xsltGenericDebugContext, + "xsltApplyTemplates: Changing document - context doc %s, xpathdoc %s\n", + ctxt->document->doc->URL, ctxt->xpathCtxt->doc->URL); #endif + } else { + ctxt->xpathCtxt->node = list->nodeTab[i]; + ctxt->document = NULL; +#ifdef WITH_XSLT_DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsltApplyTemplates: Changing document - Return tree fragment\n"); +#endif + } } xsltProcessOneNode(ctxt, list->nodeTab[i], params); } @@ -3833,7 +3842,7 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc, if ((res != NULL) && (ctxt != NULL) && (output != NULL)) { int ret; - ret = xsltCheckWrite(userCtxt->sec, userCtxt, output); + ret = xsltCheckWrite(userCtxt->sec, userCtxt, (const xmlChar *) output); if (ret == 0) { xsltTransformError(ctxt, NULL, NULL, "xsltApplyStylesheet: forbidden to save to %s\n", diff --git a/libxslt/variables.c b/libxslt/variables.c index 9f48303..98b872e 100644 --- a/libxslt/variables.c +++ b/libxslt/variables.c @@ -364,14 +364,15 @@ xsltEvalVariable(xsltTransformContextPtr ctxt, xsltStackElemPtr elem, xmlNodePtr oldInsert; xmlDocPtr oldoutput; - container = xmlNewDocNode(ctxt->document->doc, NULL, + container = xmlNewDocNode(NULL, NULL, (const xmlChar *) " fake node libxslt", NULL); if (container == NULL) return(NULL); + container->doc = (xmlDocPtr) container; container->parent = NULL; oldoutput = ctxt->output; - ctxt->output = NULL; + ctxt->output = (xmlDocPtr) container; oldInsert = ctxt->insert; ctxt->insert = container; xsltApplyOneTemplate(ctxt, ctxt->node, elem->tree, NULL, NULL); @@ -500,16 +501,17 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { xmlNodePtr oldInsert; xmlDocPtr oldoutput; - container = xmlNewDocNode(ctxt->document->doc, NULL, + container = xmlNewDocNode(NULL , NULL, (const xmlChar *) " fake node libxslt", NULL); if (container == NULL) { elem->name = name; return(NULL); } + container->doc = (xmlDocPtr) container; container->parent = NULL; oldoutput = ctxt->output; - ctxt->output = NULL; + ctxt->output = (xmlDocPtr) container; oldInsert = ctxt->insert; ctxt->insert = container; xsltApplyOneTemplate(ctxt, ctxt->node, elem->tree, NULL, NULL); diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am index 6ce4f6f..ec7d70a 100644 --- a/tests/docs/Makefile.am +++ b/tests/docs/Makefile.am @@ -110,6 +110,7 @@ EXTRA_DIST = \ bug-108.xml \ bug-109.xml \ bug-110.xml bug-110.ent \ + bug-111.xml \ character.xml \ array.xml \ items.xml diff --git a/tests/docs/bug-111.xml b/tests/docs/bug-111.xml new file mode 100644 index 0000000..b10f515 --- /dev/null +++ b/tests/docs/bug-111.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/tests/exslt/common/node-set.2.out b/tests/exslt/common/node-set.2.out index bae9ab2..8b50a79 100644 --- a/tests/exslt/common/node-set.2.out +++ b/tests/exslt/common/node-set.2.out @@ -1,2 +1,2 @@ -3 +4 diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am index bf4601b..a2665c5 100644 --- a/tests/general/Makefile.am +++ b/tests/general/Makefile.am @@ -115,6 +115,7 @@ EXTRA_DIST = \ bug-108.out bug-108.xsl \ bug-109.out bug-109.xsl \ bug-110.out bug-110.xsl \ + bug-111.out bug-111.xsl \ character.out character.xsl \ character2.out character2.xsl \ itemschoose.out itemschoose.xsl \ diff --git a/tests/general/bug-111.out b/tests/general/bug-111.out new file mode 100644 index 0000000..012d3b5 --- /dev/null +++ b/tests/general/bug-111.out @@ -0,0 +1,6 @@ + + + Test 1 + DIRTREE : true : true + Test 2 + DIRTREE : true : true diff --git a/tests/general/bug-111.xsl b/tests/general/bug-111.xsl new file mode 100644 index 0000000..20d6684 --- /dev/null +++ b/tests/general/bug-111.xsl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + Test 1 + + Test 2 + + + + + + + : : + + + + + Default Template Match Found + + + + -- 2.7.4