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

问题描述:

是否有可能使用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> 

可以设置选定元素的位置作为last-1

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

由于先生splash58,对于这样一个健壮和有效的解决方案:

内的值的元素。它像魔术一样工作。 – SIM

+0

不客气! – splash58

+0

看到先生splash58的解决方案,我试图扭曲这个表情一点点,并砰!它也有效。 “// section [@ id =”postingbody“]/text()[ - 1]” – SIM