}
public void run() throws SaxonApiException {
super.run();
TreeWriter treeWriter = new TreeWriter(runtime);
treeWriter.startDocument(step.getNode().getBaseURI());
treeWriter.addStartElement(c_param_set);
treeWriter.startContent();
for (QName param : parameters.keySet()) {
String value = parameters.get(param).getStringValue().getStringValue();
treeWriter.addStartElement(c_param);
treeWriter.addAttribute(_name, param.getLocalName());
if (param.getNamespaceURI() != null && !"".equals(param.getNamespaceURI())) {
treeWriter.addAttribute(_namespace, param.getNamespaceURI());
} else {
// I'm not really sure about this...
treeWriter.addAttribute(_namespace, "");
}
if (runtime.getAllowGeneralExpressions()) {
XdmValue xdmvalue = parameters.get(param).getValue();
XdmAtomicValue atom = null;
if (xdmvalue.size() == 1) {
XdmItem item = xdmvalue.itemAt(0);
if (item.isAtomicValue()) {
atom = (XdmAtomicValue) item;
}
}
if (atom != null && xdmvalue.size() == 1) {
treeWriter.addAttribute(_value, value);
treeWriter.startContent();
} else {
treeWriter.startContent();
XdmSequenceIterator iter = xdmvalue.iterator();
while (iter.hasNext()) {
XdmItem next = iter.next();
QName type = next.isAtomicValue() ? ((XdmAtomicValue) next).getPrimitiveTypeName() : null;
treeWriter.addStartElement(cx_item);
if (type != null) {
if ("http://www.w3.org/2001/XMLSchema".equals(type.getNamespaceURI())) {
treeWriter.addAttribute(_type, type.getLocalName());
} else {
treeWriter.addAttribute(_type, type.getClarkName());
}
}
if (next.isAtomicValue()) {
treeWriter.addAttribute(_value, next.getStringValue());
treeWriter.startContent();
} else {
treeWriter.startContent();
treeWriter.addSubtree((XdmNode) next);
}
treeWriter.addEndElement();
}
}
} else {
treeWriter.addAttribute(_value, value);
treeWriter.startContent();
}
treeWriter.addEndElement();
}
treeWriter.addEndElement();
treeWriter.endDocument();
result.write(treeWriter.getResult());
}