php - XPath return node value on sibling condition -
i'm using php parse xml , use xpath return node value based on sibling node value. i've tried googleing few hours no avail.
here's xml
<testsettings> <assets> <asset> <name>landing 1</name> <externalid>/landing1.html</externalid> <basecr>0.01</basecr> </asset> <asset> <name>landing 2</name> <externalid>/landing2.html</externalid> <basecr>0.02</basecr> </asset> <asset> <name>landing 3</name> <externalid>/landing3.html</externalid> <basecr>0.03</basecr> </asset> </assets> </testsettings>
what return basecr value based on content of externalid node. if can i'd grateful, beginning frustrating.
for example, xpath return 0.1 if sibling value in asset node '/landing1.html' or 0.3 if sibling value node '/landing3.html'
here's few of unsuccessful attempts far:
print_r($this->vxml->xpath("//assets/asset/basecr[../externalid='/landing2.html']")); print_r($this->vxml->xpath('//assets/asset[externalid/text() = "/landing2.html"]/basecr/text()')); print_r($this->vxml->xpath('//assets/asset/basecr[../text()="landing 2"]'));
many in advance,
james
use //assets/asset[externalid = '/landing1.html']/basecr
.
Comments
Post a Comment