{
if (node == null)
throw new IllegalArgumentException("Null node");
if (nsctx == null)
throw new IllegalArgumentException("Null namespace context");
TokenType tt = node.currentTokenType();
if (context != null && node.isAtSamePositionAs(context))
return ".";
switch (tt.intValue())
{
case TokenType.INT_ATTR:
QName name = node.getName();
node.toParent();
String pathToParent = generateInternal(node, context, nsctx);
return pathToParent + '/' + '@' + qnameToString(name, nsctx);
case TokenType.INT_NAMESPACE:
name = node.getName();
node.toParent();
pathToParent = generateInternal(node, context, nsctx);
String prefix = name.getLocalPart();
if (prefix.length() == 0)
return pathToParent + "/@xmlns";
else
return pathToParent + "/@xmlns:" + prefix;
case TokenType.INT_START:
case TokenType.INT_STARTDOC:
return generateInternal(node, context, nsctx);
case TokenType.INT_TEXT:
int nrOfTextTokens = countTextTokens(node);
node.toParent();
pathToParent = generateInternal(node, context, nsctx);
if (nrOfTextTokens == 0)
return pathToParent + "/text()";
else
return pathToParent + "/text()[position()=" + nrOfTextTokens + ']';
default:
throw new XPathGenerationException("Cannot generate XPath for cursor position: " +
tt.toString());
}
}