...

View Full Version : Position of Element using xpath



schokoschnute
07-03-2008, 09:24 AM
Hello :)

this is my xml-structure:


<AAA>
<BBB>
<CCC id="h" />
<CCC id="f" />
</BBB>
<BBB>
<CCC id="o" />
<CCC id="i" />
<CCC id="x" />
</BBB>
<BBB>
<CCC id="a" />
</BBB>
</AAA>


for a CCC-Element i want to know the position of the depending BBB node

ex.: the pos for CCC id="o" is 1 (equals to id="i" and id="x"), for id="a" it's 2

why gives me this code an empty result-set?


$xpath = '//CCC[@id="o"]/preceding-sibling::*';


thanks :)

Gruß
Lena

Alex Vincent
07-03-2008, 08:18 PM
I'd wager it's because BBB isn't a sibling of CCC, but a parent.

Sorry I can't give you a better answer than that.

oesxyl
07-04-2008, 06:15 PM
Hello :)

this is my xml-structure:


<AAA>
<BBB>
<CCC id="h" />
<CCC id="f" />
</BBB>
<BBB>
<CCC id="o" />
<CCC id="i" />
<CCC id="x" />
</BBB>
<BBB>
<CCC id="a" />
</BBB>
</AAA>


for a CCC-Element i want to know the position of the depending BBB node

ex.: the pos for CCC id="o" is 1 (equals to id="i" and id="x"), for id="a" it's 2

why gives me this code an empty result-set?


$xpath = '//CCC[@id="o"]/preceding-sibling::*';


thanks :)

Gruß
Lena
try to use parent instead of preceding-sibling:



$xpath = '//CCC[@id="o"]/parent::*';


in my opinion you don't need something more complicated then:



$xpath = '//BBB[CCC/@id="o"]';


try this, maybe can help:

http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/source1.html

regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum