public boolean shouldRun() throws SaxonApiException { String testExpr = ((When) step).getTest(); XdmNode doc = null; NamespaceBinding nsbinding = new NamespaceBinding(runtime, step.getNode()); Hashtable<QName,RuntimeValue> globals = parent.getInScopeOptions(); ReadablePipe reader = inputs.get("#xpath-context").firstElement(); doc = reader.read(); if (reader.moreDocuments() || inputs.get("#xpath-context").size() > 1) { throw XProcException.dynamicError(5); } // Surround testExpr with "boolean()" to force the EBV. Vector<XdmItem> results = evaluateXPath(doc, nsbinding.getNamespaceBindings(), "boolean(" + testExpr + ")", globals); if (results.size() != 1) { throw new XProcException("Attempt to compute EBV in p:when did not return a singleton!?"); } XdmAtomicValue value = (XdmAtomicValue) results.get(0); return value.getBooleanValue(); }
public boolean shouldRun() throws SaxonApiException { String testExpr = ((When) step).getTest(); XdmNode doc = null; NamespaceBinding nsbinding = new NamespaceBinding(runtime, step.getNode()); Hashtable<QName,RuntimeValue> globals = parent.getInScopeOptions(); ReadablePipe reader = inputs.get("#xpath-context").firstElement(); doc = reader.read(); if (reader.moreDocuments() || inputs.get("#xpath-context").size() > 1) { throw XProcException.dynamicError(5); } // Surround testExpr with "boolean()" to force the EBV. Vector<XdmItem> results = evaluateXPath(doc, nsbinding.getNamespaceBindings(), "boolean(" + testExpr + ")", globals); if (results.size() != 1) { throw new XProcException("Attempt to compute EBV in p:when did not return a singleton!?"); } XdmAtomicValue value = (XdmAtomicValue) results.get(0); return value.getBooleanValue(); }