2017-05-05 9 views
1

Ist es möglich, mit xpath zu dem zweitletzten Element, das in diesem Fall "778-893-3551" ist, zu kommen, ohne irgendeine Zahl am Ende des Ausdrucks hart zu codieren? Ich habe versucht, mit:Wie komme ich mit xpath zum vorletzten Wert?

//section[@id="postingbody"]/text() 

Ich möchte nicht so etwas wie folgt verwenden:

//section[@id="postingbody"]/text()[2] 

Denn wenn ein Teil fehlt oder das Element aus seiner Nummer unterscheidet sich dann die Seriennummer verwendet am Ende eines Ausdrucks bringt kein Ergebnis.

Elemente für die Werte im Bereich:

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

Antwort

2

Sie Position des ausgewählten Elements einstellen als last-1

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

Dank Sir splash58, für solch eine robuste und effektive Lösung. Es funktioniert wie Magie. – SIM

+0

Gern geschehen! – splash58

+0

Als ich die Lösung von Sir Splash58 sah, versuchte ich, diesen Ausdruck ein wenig und bam zu verdrehen! es funktioniert auch. "// section [@ id =" postingbody "]/text() [- 1]" – SIM