Fix #1282 "Condition in process can't use XForms functions"

- use DynamicVariable to scope FunctionContext
- move PooledXPathExpression to Scala
- move EXFormsSort to Scala
- some refactoring