Vadim Peretokin
Vadim Peretokin

Reputation: 2826

Specify default value in case of an empty nodeset

Using XPath 2.0, how can I specify a default value in case of an empty node set? I'd like to be able to do something to the tune of $datatypes/type[@key="somevalue"] or "default value" to have default value be returned if the key is not found.

Upvotes: 0

Views: 509

Answers (1)

hr_117
hr_117

Reputation: 9627

May be this is not what you are looking for, but I think what you need to do is to have a Conditional Expressions.

Therefore try something like this:

if ($datatypes/type[@key="somevalue"])
 than $datatypes/type[@key="somevalue"]
 else "default value"

Upvotes: 2

Related Questions