XQueryCompiler compiler = processor.newXQueryCompiler();
compiler.setErrorListener(new DefaultErrorListener());
compiler.setCompileWithTracing(isTracing);
compiler.setLanguageVersion(getConfigs().getString(config, "languageVersion", "1.0"));
XQueryExecutable executable = null;
String query = getConfigs().getString(fragment, "queryString", null);
if (query != null) {
executable = compiler.compile(query);
}
String queryFile = getConfigs().getString(fragment, "queryFile", null);
if (queryFile != null) {
executable = compiler.compile(new File(queryFile));
}
if (query == null && queryFile == null) {
throw new MorphlineCompilationException("Either query or queryFile must be defined", config);
}
if (query != null && queryFile != null) {
throw new MorphlineCompilationException("Must not define both query and queryFile at the same time", config);
}
XQueryEvaluator evaluator = executable.load();
Config variables = getConfigs().getConfig(fragment, "externalVariables", ConfigFactory.empty());
for (Map.Entry<String, Object> entry : new Configs().getEntrySet(variables)) {
XdmValue xdmValue = XdmNode.wrap(new UntypedAtomicValue(entry.getValue().toString()));
evaluator.setExternalVariable(new QName(entry.getKey()), xdmValue);
}