XPATH to select all not null childs plus a default value when not found

XPATH to select all not null childs plus a default value when not found

是否有 XPATH return 所有非空值 someChild 加上找不到值时的默认值?

<someFather>
    <someChild/>
    <someChild/>
    <someChild>some value</someChild>
    <someChild/>
    <someChild>some other value</someChild>
    <someChild/>
</someFather>

我想得到:

""
""
some value
""
some other value
""

,或

"not-found"
"not-found"
some value
"not-found"
some other value
"not-found"

试试下面的表达式:

/someFather/(someChild/string(), '') 
/someFather/someChild/(text()/string(), "not-found")[1]

这是精心编写的,以避免违反“/”的 RHS 不能 select 节点和原子值的混合的规则。在 3.0 中你可以使用 "!"运算符:

/someFather/someChild ! (text(), "not-found")[1]