public static SequenceIterator query(XPathContext context, XQueryExpression query,
Item source, SequenceIterator params) throws XPathException {
if (query == null) {
return null;
}
DynamicQueryContext dqc = new DynamicQueryContext(context.getConfiguration());
if (source != null) {
dqc.setContextItem(source);
}
NamePool pool = context.getConfiguration().getNamePool();
while (true) {
Item param = params.next();
if (param == null) {
break;
}
if (param instanceof NodeInfo) {
switch (((NodeInfo)param).getNodeKind()) {
case Type.ELEMENT:
case Type.ATTRIBUTE:
Value val = ((NodeInfo)param).atomize();
dqc.setParameter(pool.getClarkName(((NodeInfo)param).getNameCode()), val);
break;
case Type.DOCUMENT:
AxisIterator kids = ((NodeInfo)param).iterateAxis(Axis.CHILD, NodeKindTest.ELEMENT);
while (true) {
NodeInfo kid = (NodeInfo)kids.next();
if (kid == null) {
break;
}
Value val2 = ((NodeInfo)param).atomize();
dqc.setParameter(pool.getClarkName(kid.getNameCode()), val2);
}
break;
default:
throw new XPathException(
"Parameters passed to saxon:query() must be element, attribute, or document nodes");