private When readWhen(Step parent, XdmNode node) { checkAttributes(node, new String[] { "test" }, false); String stepName = checkNCName(node.getAttributeValue(px_name)); String testExpr = node.getAttributeValue(new QName("test")); When step = new When(runtime, node, stepName); checkExtensionAttributes(node, step); step.setTest(testExpr); step.setParentDecl((DeclareStep) parent); step.parent = parent; Vector<XdmNode> rest = readSignature(step); if (rest == null) { throw XProcException.staticError(15, node, "A p:when must contain a subpipeline."); } for (XdmNode substepNode : rest) { Step substep = readStep(step, substepNode); step.addStep(substep); } step.checkPrimaryIO(); return step; }
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(); }
private When readWhen(Step parent, XdmNode node) { checkAttributes(node, new String[] { "test" }, false); String stepName = checkNCName(node.getAttributeValue(px_name)); String testExpr = node.getAttributeValue(new QName("test")); When step = new When(runtime, node, stepName); checkExtensionAttributes(node, step); step.setTest(testExpr); step.setParentDecl((DeclareStep) parent); step.parent = parent; Vector<XdmNode> rest = readSignature(step); if (rest == null) { throw XProcException.staticError(15, node, "A p:when must contain a subpipeline."); } for (XdmNode substepNode : rest) { Step substep = readStep(step, substepNode); step.addStep(substep); } step.checkPrimaryIO(); return step; }