Reputation: 524
Is there an XPATH to return all non-null someChild
plus a default value for when the value on is not found?
<someFather>
<someChild/>
<someChild/>
<someChild>some value</someChild>
<someChild/>
<someChild>some other value</someChild>
<someChild/>
</someFather>
I would like to get:
""
""
some value
""
some other value
""
, or
"not-found"
"not-found"
some value
"not-found"
some other value
"not-found"
Upvotes: 1
Views: 98
Reputation: 163418
/someFather/someChild/(text()/string(), "not-found")[1]
This is carefully written to avoid breaking the rule that the RHS of "/" cannot select a mixture of nodes and atomic values. In 3.0 you could use the "!" operator:
/someFather/someChild ! (text(), "not-found")[1]
Upvotes: 4
Reputation: 786
Try the following expression:
/someFather/(someChild/string(), '')
Upvotes: 3