Namespaces and variables both need to be declared (on the XPathCompiler) before the XPath expression is compiled. You can reuse the XPathCompiler to compile many XPath expressions, and its state (including declared variables and namespaces) is retained between compilations.
 
Value for variables need to be set up on the XPathSelector before the expression is evaluated. You can reuse the XPathSelector (and it retains the variable values) provided that you don't try to use it concurrently in different threads.
 
Hope this answers the question!
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of martin.me.roberts@bt.com
Sent: 15 July 2008 15:26
To: saxon-help@lists.sourceforge.net
Subject: [saxon] S9APIXpath and namespaces and variables

Hi,
 I am trying to improve performance of my app by using the saxon API on JDOM documents rather than JAXEN.
 
  In the process I have a number of questions?
 
  1) Do I need to explicitly set up namespace context?
  2) If I do when should I do it?  Can it be done before the load of the compiled xpath?
  3) When do I set up variables? Can I do this before the load()?
 
  The reason for wanting to do this before the load is that I want to reduce the amount of setup for each new XPATH as I have literally hundreds to process against the same document with the same namespace and variable contexts?
 
Martin