class XQueryExpressionEvaluator {

    public String evaluateXQuery(final String xml, final String query) throws SaxonApiException {
        Processor processor = processorFactory.createProcessor();
        XQueryCompiler xqueryCompiler = processor.newXQueryCompiler();
        xqueryCompiler.setErrorListener(errorListener);
        XQueryExecutable xqueryExec = xqueryCompiler.compile(query);
        XQueryEvaluator xqueryEval = xqueryExec.load();
        xqueryEval.setErrorListener(errorListener);
        SAXSource requestXml = saxSourceFactory.createSAXSource(inputSourceFactory.createInputSource(xml));
        xqueryEval.setSource(requestXml);
        ByteArrayOutputStream baos = byteArrayOutputStreamFactory.createByteArrayOutputStream();
        Serializer ser = serializerFactory.createSerializer(baos);
        xqueryEval.setDestination(ser);
        xqueryEval.run();
        return baos.toString();
    }

}