A question on the eclipse web tools news group asked about evaluating the current context node in PsychoPath. The Default is for PsychoPath to use the Document as it's context and evaluate from there. There are a couple of ways to evaluate using a given Node as the starting point.

  1. Create an implementation of the DefaultDynamicContext that takes a NodeType as a parameter instead of just a Document.
  2. Use an XPath variable and set the value of the variable to the NodeType to begin.
The latter is much quicker to setup and can be setup like the following:



DynamicContext dc = new DefaultDynamicContext(schema, domDoc);
dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");

dc.add_function_library(new FnFunctionLibrary());
dc.add_function_library(new XSCtrLibrary());

ElementType elementType = new ElementType(domDoc.getDocumentElement(), 0);
dc.set_variable(new QName("input-context"), elementType, 0);



This then allows for the XPath expression to be written as:



$input-context/element



The evaluation of the expression will begin with the Document's Root Element instead of at the Document level. You may do this for any node type that you wish evaluation to begin.