}
XdmNode element = null;
Iterator<XdmItem> values = selector.iterator();
while (values.hasNext()) {
XdmItem item = values.next();
if (element != null || item.isAtomicValue()) {
throw XProcException.dynamicError(9);
}
element = (XdmNode) item;
if (element.getNodeKind() != XdmNodeKind.ELEMENT) {
throw XProcException.dynamicError(9);
}
}
if (element == null) {
throw XProcException.dynamicError(9);
}
XdmSequenceIterator nsIter = element.axisIterator(Axis.NAMESPACE);
while (nsIter.hasNext()) {
XdmNode ns = (XdmNode) nsIter.next();
QName prefix = ns.getNodeName();
localBindings.put(prefix == null ? "" : prefix.getLocalName(),ns.getStringValue());
}
} catch (SaxonApiException sae) {
throw new XProcException(sae);
}
} else if (nsbinding.getNamespaceBindings() != null) {
Hashtable<String,String> bindings = nsbinding.getNamespaceBindings();
for (String prefix : bindings.keySet()) {
if ("".equals(prefix) || prefix == null) {
// nop; the default namespace never plays a role in XPath expression evaluation
} else {
localBindings.put(prefix,bindings.get(prefix));
}
}
}
// Remove the excluded ones
HashSet<String> prefixes = new HashSet<String> ();
for (String uri : nsbinding.getExcludedNamespaces()) {
for (String prefix : localBindings.keySet()) {
if (uri.equals(localBindings.get(prefix))) {
prefixes.add(prefix);
}
}
}
for (String prefix : prefixes) {
localBindings.remove(prefix);
}
// Add them to the bindings for this value, making sure there are no errors...
for (String pfx : localBindings.keySet()) {
if (nsBindings.containsKey(pfx) && !nsBindings.get(pfx).equals(localBindings.get(pfx))) {
throw XProcException.dynamicError(13);
}
nsBindings.put(pfx,localBindings.get(pfx));
}
}
String select = var.getSelect();
Vector<XdmItem> results = evaluateXPath(doc, nsBindings, select, globals);
String value = "";
try {
for (XdmItem item : results) {
if (item.isAtomicValue()) {
value += item.getStringValue();
} else {
XdmNode node = (XdmNode) item;
if (node.getNodeKind() == XdmNodeKind.ATTRIBUTE
|| node.getNodeKind() == XdmNodeKind.NAMESPACE) {
value += node.getStringValue();