如何使用 XPath 和 Saxon 获取属性值
How to get the value of an attribute using XPath and Saxon
我正在使用 Saxon HE 9.6.0.6 并尝试使用 XPath 检索属性的 值。
鉴于 XML 和以下查询:
<Pol>
<ISR>
<Code Val='Test1'/>
<Text Val='test 1'/>
</ISR>
<ISR>
<Code Val = 'Test2' />
<Text Val = 'test 2' />
</ISR>
</Pol>
//Pol/ISR/Code[@Val='Test2']/../Text/@Val
这给了我属性("Val='test 2'")但我想要值(即'test 2') .我想我需要使用 xpath 函数,但不确定如何在 Saxon 中添加它们。
如果您确定只select编辑了一个或零个属性或//Pol/ISR/Code[@Val='Test2']/../Text/@Val/string()
到select一系列字符串值,则可以使用string(//Pol/ISR/Code[@Val='Test2']/../Text/@Val)
。
我正在使用 Saxon HE 9.6.0.6 并尝试使用 XPath 检索属性的 值。
鉴于 XML 和以下查询:
<Pol>
<ISR>
<Code Val='Test1'/>
<Text Val='test 1'/>
</ISR>
<ISR>
<Code Val = 'Test2' />
<Text Val = 'test 2' />
</ISR>
</Pol>
//Pol/ISR/Code[@Val='Test2']/../Text/@Val
这给了我属性("Val='test 2'")但我想要值(即'test 2') .我想我需要使用 xpath 函数,但不确定如何在 Saxon 中添加它们。
如果您确定只select编辑了一个或零个属性或//Pol/ISR/Code[@Val='Test2']/../Text/@Val/string()
到select一系列字符串值,则可以使用string(//Pol/ISR/Code[@Val='Test2']/../Text/@Val)
。