2017-05-05 96 views
1

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

回答

2

可以設置選定元素的位置作爲last-1

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

由於先生splash58,對於這樣一個健壯和有效的解決方案:

內的值的元素。它像魔術一樣工作。 – SIM

+0

不客氣! – splash58

+0

看到先生splash58的解決方案,我試圖扭曲這個表情一點點,並砰!它也有效。 「// section [@ id =」postingbody「]/text()[ - 1]」 – SIM

相關問題