Question

I have got this xml file:

<?xml version="1.0" encoding="US-ASCII"?>
<?xml-stylesheet type="text/css" href="positions-zaehlweise.css"?>
<ul>
<li>A</li> 
<li>             
 <ol>
   <li>B</li>
   <li>C</li>
 </ol>
</li>
<li>D</li>
</ul>

and this xpath query:

/child::ul/descendant-or-self::*/child::li[position()=1]

I am getting from this query: A and B.

but i somehow dont understand how it does this. With /descendant-or-self it is taking as self the A, right? then it goes down the list and takes all. then how does it compare, my vision is this:

self             descendant
----------------------------
A,D                 B, C

am i right? can someone please explain me in short how this worked? thanks in tons

Was it helpful?

Solution

/child::ul returns the ul.

descendant-or-self::* returns self (ul again) plus all its descendants (li-A, li-ol, ol, li-B, li-C, li-D).

child::li moves to children of the previous elements that are li, which means li-A, li-ol and li-D for ul, andli-Bandli-Cforol`.

[position()=1] only selects those that are the first such child, i.e. li-A and li-B.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top