如何获取最后一个元素的属性值



输入XML

<pageMeta>
  <trail target="/">SAIR Home</trail>
  <trail target="/handle/10862/1">SEAFDEC Aquaculture Department</trail>
  <trail target="/handle/10862/46">SEAFDEC/AQD Publications</trail>
  <trail target="/handle/10862/85">Institutional and Meeting Reports</trail>
  <trail target="/handle/10862/699">Institutional Reports</trail>
  <trail target="/handle/10862/527">Annual Reports</trail>
</pageMeta>

使用select="pageMeta/trail[@target][last()],我得到Annual Reports值。如何获得最后一个@target属性的值,即/handle/10862/527 ?

您可以简单地将属性名作为XPath表达式的最后一步来返回属性:

select="pageMeta/trail[@target][last()]/@target"

相关内容

  • 没有找到相关文章

最新更新