如何使用xpath从节点获取属性值?

Ser*_*ejs 18 xml string xpath return-value

完全是xpath的新手.

我有xml:

<Values>
   <Value Value="a" CustomAtr="1" />
   <Value Value="b" CustomAtr="2" />
   <Value Value="c" CustomAtr="3" />
</Values>
Run Code Online (Sandbox Code Playgroud)

要通过索引获取价值,我可以使用: string(/*/Value[1]/@CustomAtr)

是否有可能通过钥匙获得价值?热得到CustomAtr价值在哪里Value="b"

谢谢

小智 40

这应该做的伎俩:

string(//Value[@Value='b']/@CustomAttr)
Run Code Online (Sandbox Code Playgroud)