简体   繁体   中英

How to get the attribute value of the last element?

Input 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>

Using select="pageMeta/trail[@target][last()] , I get the Annual Reports value. How can I get the value of the last @target attribute which is /handle/10862/527 ?

Thanks in advance.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM