* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
XObject arg = (XObject) this.getArg0().execute(xctxt);
String base = "";
Expression arg1Expr = this.getArg1();
if (null != arg1Expr)
{
// The URI reference may be relative. The base URI (see [3.2 Base URI])
// of the node in the second argument node-set that is first in document
// order is used as the base URI for resolving the
// relative URI into an absolute URI.
XObject arg2 = arg1Expr.execute(xctxt);
if (XObject.CLASS_NODESET == arg2.getType())
{
int baseNode = arg2.iter().nextNode();
if (baseNode == DTM.NULL)
{
// See http://www.w3.org/1999/11/REC-xslt-19991116-errata#E14.
// If the second argument is an empty nodeset, this is an error.
// The processor can recover by returning an empty nodeset.
warn(xctxt, XSLTErrorResources.WG_EMPTY_SECOND_ARG, null);
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
return nodes;
} else{
DTM baseDTM = xctxt.getDTM(baseNode);
base = baseDTM.getDocumentBaseURI();
}
// %REVIEW% This doesn't seem to be a problem with the conformance
// suite, but maybe it's just not doing a good test?
// int baseDoc = baseDTM.getDocument();
//
// if (baseDoc == DTM.NULL /* || baseDoc instanceof Stylesheet -->What to do?? */)
// {
//
// // base = ((Stylesheet)baseDoc).getBaseIdentifier();
// base = xctxt.getNamespaceContext().getBaseIdentifier();
// }
// else
// base = xctxt.getSourceTreeManager().findURIFromDoc(baseDoc);
}
else
{
//Can not convert other type to a node-set!;
arg2.iter();
}
}
else
{
// If the second argument is omitted, then it defaults to
// the node in the stylesheet that contains the expression that
// includes the call to the document function. Note that a
// zero-length URI reference is a reference to the document
// relative to which the URI reference is being resolved; thus
// document("") refers to the root node of the stylesheet;
// the tree representation of the stylesheet is exactly
// the same as if the XML document containing the stylesheet
// was the initial source document.
assertion(null != xctxt.getNamespaceContext(), "Namespace context can not be null!");
base = xctxt.getNamespaceContext().getBaseIdentifier();
}
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM mnl = nodes.mutableNodeset();
DTMIterator iterator = (XObject.CLASS_NODESET == arg.getType())
? arg.iter() : null;
int pos = DTM.NULL;
while ((null == iterator) || (DTM.NULL != (pos = iterator.nextNode())))
{
XMLString ref = (null != iterator)
? xctxt.getDTM(pos).getStringValue(pos) : arg.xstr();
// The first and only argument was a nodeset, the base in that
// case is the base URI of the node from the first argument nodeset.
// Remember, when the document function has exactly one argument and
// the argument is a node-set, then the result is the union, for each
// node in the argument node-set, of the result of calling the document
// function with the first argument being the string-value of the node,
// and the second argument being a node-set with the node as its only
// member.
if (null == arg1Expr && DTM.NULL != pos)
{
DTM baseDTM = xctxt.getDTM(pos);
base = baseDTM.getDocumentBaseURI();
}
if (null == ref)
continue;