I had to put this into use today in a BizTalk map (inline XSLT). Since this is in BizTalk, I was limited to XPath 1.0 as a solution.
This is the problem/solution from StackOverflow:
Say I have a pair of XML documents
I want an XPath (Version 1.0 only) that returns “mystring” for the first document and “not-found” for the second.
In XPath 1.0, use:
concat(/Foo/Baz, substring(‘not-found’, 1 div not(/Foo/Baz)))
If you want to handle the posible empty Baz element, use:
concat(/Foo/Baz, substring(‘not-found’, 1 div not(/Foo/Baz[node()])))
With this input:
Result: not-found string data type.
This worked beautifully!