I'm already familiar with the implementation of the XPathAPI and I've already found how to retrieve the VariableStack from the XPathContext. The problem is that once you got your VariableStack instance you're not sure you will use it in the right way : for example, the setGlobalVariable() method requires two arguments : an XObject (that's OK), and an index. What value should I give to the index parameter ? And anyway how shall I bind this index with a QName, so as to access it through XPath $-prefixed variables ? I'll try to step into the XSLT engine code to see how it does it, yet I fear it will be a bit difficult ...
-----Message d'origine----- De : Joseph Kesselman [mailto:[EMAIL PROTECTED] Envoye : mardi 28 octobre 2003 15:30 A : [EMAIL PROTECTED] Objet : RE: binding variables to values in XPath > I need to know how to > define XPath variables outside a XSLT, that means : > - within the XPath expression itself (I think there's finally no way) There's no way in XPath 1.0. I haven't checked whether Xpath 2.0 adds anything along those lines. > - through the Xalan API (I found a VariableStack class, but I don't > understand how to use it, or if I should use it in my purpose anyway). It can be done -- our XSLT engine does it, obviously, both from within XSLT and via the setParameter() call -- but we don't seem to have a stand-alone example on our website. We probably should... If you look at the source code for the XPathAPI convenience wrapper, you'll see that it basically creates a parsed XPath object and an XPathContext object, sets the source document into the XPathContext, and runs the XPath's execute() method over that. To set variables, I believe you'd retrieve the XPathContext's variable stack (via getVarStack()) and use it to assert them before executing the XPath.