如何使用xpath获取倒数第二个值?

时间:2017-05-05 10:04:27

标签: xpath

是否有可能到达第二个最后一个元素,在这种情况下" 778-893-3551"使用xpath而不在表达式的末尾硬编码任何数字? 我试过了:

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

1 个答案:

答案 0 :(得分:2)

您可以将所选元素的位置设置为last-1

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