How to get the nearest ancestor or child of an ancestor with xpath
问题 Look at <bookmark/> . The desired output I want is the id with value 5 <xsl:value-of select="//bookmark/ancestor::*[@id][1]/@id"/> only gives me 4 <?xml version="1.0" encoding="UTF-8"?> <content> <section id="1"> <section id="2"/> <section id="3"/> <section id="9"/> </section> <section id="4"> <section> <section id="10"/> <section id="5"/> <section> <bookmark/> <section id="6"> <section id="7"> <section id="8"/> </section> </section> </section> </section> </section> </content> 回答1: The way I