if (source == null) {
return null;
}
try {
Transformer transformer = templates.newTransformer();
TinyBuilder builder = new TinyBuilder();
builder.setPipelineConfiguration(context.getController().makePipelineConfiguration());
while (true) {
Item param = params.next();
if (param == null) {
break;
}
if (param instanceof NodeInfo) {
switch (((NodeInfo)param).getNodeKind()) {
case Type.ELEMENT:
case Type.ATTRIBUTE:
setTransformerParameter(param, transformer, source);
break;
case Type.DOCUMENT:
AxisIterator kids = ((NodeInfo)param).iterateAxis(Axis.CHILD, NodeKindTest.ELEMENT);
while (true) {
NodeInfo kid = (NodeInfo)kids.next();
if (kid == null) {
break;
}
setTransformerParameter(kid, transformer, source);
}
break;
default:
throw new XPathException(
"Parameters passed to saxon:transform() must be element, attribute, or document nodes");
}
} else {
throw new XPathException("Parameters passed to saxon:transform() must be nodes");
}
}
transformer.transform(source, builder);
return (DocumentInfo)builder.getCurrentRoot();
} catch (TransformerException e) {
throw XPathException.makeXPathException(e);
}
}