diff --git a/libxslt/variables.c b/libxslt/variables.c
index 564229366f81abe571a4d7f8a2b51154e3cc1b2b_bGlieHNsdC92YXJpYWJsZXMuYw==..b2f0a9697ba8967d12d98f2022b1c7f3972ea354_bGlieHNsdC92YXJpYWJsZXMuYw== 100644
--- a/libxslt/variables.c
+++ b/libxslt/variables.c
@@ -963,6 +963,8 @@
 		xmlDocPtr container;
 		xmlNodePtr oldInsert;
 		xmlDocPtr  oldOutput;
+                const xmlChar *oldLastText;
+                int oldLastTextSize, oldLastTextUse;
 		xsltStackElemPtr oldVar = ctxt->contextVariable;
 
 		/*
@@ -988,6 +990,9 @@
 
 		oldOutput = ctxt->output;
 		oldInsert = ctxt->insert;
+                oldLastText = ctxt->lasttext;
+                oldLastTextSize = ctxt->lasttsize;
+                oldLastTextUse = ctxt->lasttuse;
 
 		ctxt->output = container;
 		ctxt->insert = (xmlNodePtr) container;
@@ -1002,6 +1007,9 @@
 		ctxt->contextVariable = oldVar;
 		ctxt->insert = oldInsert;
 		ctxt->output = oldOutput;
+                ctxt->lasttext = oldLastText;
+                ctxt->lasttsize = oldLastTextSize;
+                ctxt->lasttuse = oldLastTextUse;
 
 		result = xmlXPathNewValueTree((xmlNodePtr) container);
 	    }