RE: [xml] Using variables with XPath expressions

On Tue, Jul 03, 2001 at 04:00:02PM -0600, Vakoc, Mark wrote:
My fix (I believe) was to correct xmlXPathCompOpEval to use a copy of the
variable value rather than the value directly.  I have done a fair amount
testing using this and all my expressions using variables return the
expected results.  

     case XPATH_OP_VARIABLE: {
         if (op->ch1 != -1)
             xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
         if (op->value5 == NULL)
--           valuePush(ctxt,
--               xmlXPathVariableLookup(ctxt->context, op->value4));
++           valuePush(ctxt,xmlXPathObjectCopy(
xmlXPathVariableLookup(ctxt->context, op->value4)) );

Daniel - Can you confirm that this is the right approach.

That would be one way to do it, but would change the interface between
libxml and libxslt (which uses the xmlXPathRegisterVariableLookup() 
mechanism and where the registered lookup function does the copy), 
so I would rather fix the default Variable lookup to do this copy
and hence change the end of xmlXPathVariableLookupNS() to

   if (ctxt->varHash == NULL)
   if (name == NULL)

               xmlHashLookup2(ctxt->varHash, name, ns_uri)));

This works for me.  I tested it in my app (nasty xpath expressions utilizing
6-8 variables) and it worked without issue.  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]