use of org.apache.xpath.jaxp.JAXPPrefixResolver in project nokogiri by sparklemotion.
the class XmlXpathContext method tryGetNodeSet.
private IRubyObject tryGetNodeSet(ThreadContext context, String expr, NokogiriXPathFunctionResolver fnResolver) throws TransformerException {
final Node contextNode = this.context.node;
final JAXPPrefixResolver prefixResolver = new JAXPPrefixResolver(nsContext);
XPath xpathInternal = new XPath(expr, null, prefixResolver, XPath.SELECT);
// We always need to have a ContextNode with Xalan XPath implementation
// To allow simple expression evaluation like 1+1 we are setting
// dummy Document as Context Node
final XObject xobj;
if (contextNode == null)
xobj = xpathInternal.execute(getXPathContext(fnResolver), DTM.NULL, prefixResolver);
else
xobj = xpathInternal.execute(getXPathContext(fnResolver), contextNode, prefixResolver);
switch(xobj.getType()) {
case XObject.CLASS_BOOLEAN:
return context.getRuntime().newBoolean(xobj.bool());
case XObject.CLASS_NUMBER:
return context.getRuntime().newFloat(xobj.num());
case XObject.CLASS_NODESET:
XmlNodeSet xmlNodeSet = XmlNodeSet.create(context.getRuntime());
xmlNodeSet.setNodeList(xobj.nodelist());
xmlNodeSet.initialize(context.getRuntime(), this.context);
return xmlNodeSet;
default:
return context.getRuntime().newString(xobj.str());
}
}
Aggregations