If you have nodes that are not attached to a document (or if you are
looking at the root node of a document), then it is of course impossible to
find a (relative) XPath that matches this node. I assume you're looking
for a step-by-step path expression rather than something like
which would be an expression that matches any node in a document.
The real question is: Why are the nodes you're looking at not attached
to a document, and what do you need the XPath for?