如何使用xpath获取最后一个值?

如何使用xpath获取最后一个值?,xpath,Xpath,是否可以使用xpath访问最后一个元素,即本例中的“778-893-3551”,而不在表达式末尾硬编码任何数字? 我试过: //section[@id="postingbody"]/text() 我不想用这样的东西: //section[@id="postingbody"]/text()[2] 因为,如果缺少任何项或项与其编号不同,则表达式末尾使用的序列号不会产生任何结果 元素中的值: <section id="postingbody">Located in the heart

是否可以使用xpath访问最后一个元素,即本例中的“778-893-3551”,而不在表达式末尾硬编码任何数字? 我试过:

//section[@id="postingbody"]/text()
我不想用这样的东西:

//section[@id="postingbody"]/text()[2]
因为,如果缺少任何项或项与其编号不同,则表达式末尾使用的序列号不会产生任何结果

元素中的值:

<section id="postingbody">Located in the heart of Guildford. Surrey, Built in 2014, looks and feels new. No GST. Still under 2/5/10 National New Home Warranty. Timeless Craftsman-style architecture, with wood and hardy plank exterior. Open floor plan with 9' ceiling on the main floor. 30" ceran top electric range self-cleaning oven and stainless steel 3 door fridge. Contemporary Real Maple cabinets. 2 Storey clubhouse with Gym, Sauna, Party hall &amp; Guest Suite. Easy access to No. walking distance to Guildford mall, library and all the services you desire, very convenient location, 8 minutes drive to a skytrain station, 2 minutes drive to hwy 1.<br>
2 covered parking.<br>
10 minutes drive from Coquitlam Centre.<br>
<br>
Call to make an appointment to view the place.<br>
<br>
Ahmed Afandi<br>
778-893-3551<br>
Kore Realty Central</section>
位于吉尔福德市中心。萨里,建于2014年,外观和感觉都很新。没有消费税。仍在2/5/10国家新房保修期内。永恒的工匠风格建筑,木质和耐寒木板外观。开放式楼层平面图,主楼层天花板为9英尺。30ceran top电动自洁烤箱和不锈钢三门冰箱。当代真正的枫木橱柜。2层会所,带健身房、桑拿、宴会厅和;客房套房。方便前往第号公路,步行即可到达吉尔福德购物中心、图书馆和您想要的所有服务,地理位置非常方便,距离空中火车站8分钟车程,距离1号高速公路2分钟车程。
2有盖停车场。
从科基特兰中心开车10分钟。

打电话预约参观这个地方。

艾哈迈德·阿凡迪
778-893-3551
韩国房地产中心
您可以将所选元素的位置设置为
last-1

//section[@id="postingbody"]/text()[position()=last()-1]

我从未使用过这样的语法:)。我需要了解一下,也许,这取决于实现情况。//section[@id=“postingbody”]/text()[last()-1]也适用于meI尝试了类似Pavel Savine编写的东西,但得到了空值。必须按照splash58的指示使用
position()=
,才能使其正常工作。另外,您可能需要//text()(双斜杠)