// If $relative is the empty sequence, the empty sequence is returned.
Item firstItem = argv.getItem(0);
if(firstItem.isEmpty()) {
return ValueSequence.EMPTY_SEQUENCE;
}
final URI relative;
String relativeStr = firstItem.stringValue();
try {
if(relativeStr.length() == 0) {
relative = null;
} else {
relative = new URI(relativeStr);
if(relative.isAbsolute()) {// If $relative is an absolute URI reference, it is returned unchanged.
return AnyURIValue.valueOf(relative);
}
}
} catch (URISyntaxException e) {
throw new DynamicError("err:FORG0002", "Invalid URI form: " + relativeStr);
}
final URI baseUri;
final int arglen = argv.size();
if(arglen == 2) {
Item secondItem = argv.getItem(1);
String baseStr = secondItem.stringValue();
baseUri = URI.create(baseStr);
} else {
baseUri = dynEnv.getStaticContext().getBaseURI();
if(baseUri == null) {
throw new DynamicError("err:FONS0005", "BaseUri is not set in the static context.");
}
}
if(relative == null) {// If $relative is the zero-length string, returns the value of the base-uri property.
return AnyURIValue.valueOf(baseUri);
}
final URI resolved = baseUri.resolve(relative);
return AnyURIValue.valueOf(resolved);
}