Hi Christian, Thank you. This is very useful. One issue, though: in my test, it looks like the ancestors of the element that is processed by the query are not available/accessible. What am I missing? Best regards, Johannes -----Ursprüngliche Nachricht----- Von: Christian Grün [mailto:christian.gruen@gmail.com] Gesendet: Dienstag, 23. Mai 2017 12:43 An: Johannes Echterhoff <echterhoff@interactive-instruments.de> Cc: basex-talk@mailman.uni-konstanz.de Betreff: Re: [basex-talk] Evaluating XPath within custom QueryModule Hi Johannes, Welcome to the list.
However, I wonder if it is possible to evaluate the expression also within the query module itself, i.e. when method “parse” is called. Is there a way to do so?
Absolutely. You find some examples in [1]. If you your class extends the QueryModule class – which is always recommendable – a function could look as follows: import org.basex.core.Context; import org.basex.query.QueryModule; import org.basex.query.QueryProcessor; import org.basex.query.value.Value; public class Module extends QueryModule { public Value elementName(Value elem) throws Exception { // Your query String query = "declare variable $elem external;" + "name($elem), (: element bound to variable :)" + "name(.) (: element bound to context :)"; Context ctx = queryContext.context; QueryProcessor qp = new QueryProcessor(query, ctx); // Bind to context: qp.bind("elem", elem); qp.context(elem); Value value = qp.value(); return value; } } Hope this helps, Christian [1] https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/or...