diff --git a/libexslt/functions.c b/libexslt/functions.c index 075e2366..41d37493 100644 --- a/libexslt/functions.c +++ b/libexslt/functions.c @@ -291,7 +291,7 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathObjectPtr oldResult, ret; exsltFuncData *data; exsltFuncFunctionData *func; - xmlNodePtr paramNode, oldInsert, fake; + xmlNodePtr paramNode, oldInsert, oldXPNode, fake; int oldBase; void *oldCtxtVar; xsltStackElemPtr params = NULL, param; @@ -360,6 +360,9 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) { } tctxt->depth++; + /* Evaluating templates can change the XPath context node. */ + oldXPNode = tctxt->xpathCtxt->node; + /* * We have a problem with the evaluation of function parameters. * The original library code did not evaluate XPath expressions until @@ -446,6 +449,7 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) { data->ctxtVar = oldCtxtVar; if (params != NULL) xsltFreeStackElemList(params); + tctxt->xpathCtxt->node = oldXPNode; if (data->error != 0) goto error; diff --git a/tests/docs/bug-216.xml b/tests/docs/bug-216.xml new file mode 100644 index 00000000..d128aecc --- /dev/null +++ b/tests/docs/bug-216.xml @@ -0,0 +1 @@ + diff --git a/tests/general/bug-216.out b/tests/general/bug-216.out new file mode 100644 index 00000000..40f6b10c --- /dev/null +++ b/tests/general/bug-216.out @@ -0,0 +1,2 @@ + +10 diff --git a/tests/general/bug-216.xsl b/tests/general/bug-216.xsl new file mode 100644 index 00000000..50cc4b11 --- /dev/null +++ b/tests/general/bug-216.xsl @@ -0,0 +1,11 @@ + + + + + + 10 + + + + +