Do what's inconvenient with XPath
Implement the javax.xml.xpath.XPathFunction
interface.
public Object evaluate(List args) throws XPathFunctionException
Return one of these five types:
java.lang.String
java.lang.Double
java.lang.Boolean
org.w3c.dom.Nodelist
org.w3c.dom.Node