czerwin
czerwin

Reputation: 1000

XQuery 3 - get string representation of a node path

I have a function that accepts a node as an argument. I would like to get the string representation of the path whether it exists or not.

declare function mylib:getString($node) as xs:string {
    return /*the string representation of the node's path*/
};

And sample invocation:

mylib:getString($xmlMessage/some/dummy/element);

Above example should return /some/dummy/element string. I have already tried two solutions:

  1. Function path() (e.g. /some/node/path()).
  2. Function path-to-node(...) within FunctX library but with no success.

Unfortunately, both functions work on existing nodes only.

Upvotes: 0

Views: 867

Answers (1)

Michael Kay
Michael Kay

Reputation: 163262

If /some/dummy/element returns nothing, there is no way of finding out which particular nothing it returned. If the path expression selects nothing, the result is an empty sequence, and you can't apply a function to an empty sequence to determine where the empty sequence came from.

Upvotes: 1

Related Questions