//b[1]//c gives different results if the first b is nested in anotherelement

Y

yawnmoth

<a>
<b>
<c/><c/>
</b>
<b>
<c/><c/><c/>
</b>
<b>
<c/>
</b>
</a>

Doing //b[1]//c on that yields two items. If, however, I put the
first <b></b> within a <d></d>, I get five items. My question is...
why?

Here's what I mean by "put the first <b></b> within a <d></d>":

<a>
<d>
<b>
<c/><c/>
</b>
</d>
<b>
<c/><c/><c/>
</b>
<b>
<c/>
</b>
</a>

Why does that return 5 items when the first only returns 2?
 
D

David Carlisle

yawnmoth said:
<a>
<b>
<c/><c/>
</b>
<b>
<c/><c/><c/>
</b>
<b>
<c/>
</b>
</a>

Doing //b[1]//c on that yields two items. If, however, I put the
first <b></b> within a <d></d>, I get five items. My question is...
why?

Here's what I mean by "put the first <b></b> within a <d></d>":

<a>
<d>
<b>
<c/><c/>
</b>
</d>
<b>
<c/><c/><c/>
</b>
<b>
<c/>
</b>
</a>

Why does that return 5 items when the first only returns 2?


//b[1] means select all b that are the first b child of their parent.
If you want to select the first b descendant use
/descendant::b[1]

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top