Question

My XML Structure is like

<root>
  <elem1>..</elem1>
  <elem1>..</elem1>
  *<elem1>..</elem1>*
  <elem2>
    <elem1>..</elem1>
    <elem1>..</elem1>
    ¬ <elem1>..</elem1> ¬
  </elem2>
</root>

I need to select the last elem1 of the immediate child of root (marked with * *).

I want to do it in QueryPath - http://querypath.org. But JQuery syntaxes could also help.

$root->find('elem1')->last();
$root->find('elem1:last);
$root->find('elem1:last-child); 

All the above three selects the elem1 marked with ¬

Était-ce utile?

La solution 3

This works

$root->find('elem1:last-of-type'); 

Thanks David Thomas for Proof of Concept http://jsfiddle.net/davidThomas/RehZ7/

Autres conseils

You can use last method:

$('root > elem1').last();

By looking at QueryPath API it seems you can code:

$root->children('elem1')->last()

last() method that reduces the set of matched elements to the final one in the set, can do it for you like below;

$('root > elem1').last();

OR

You can use :last-child Selector that selects all elements that are the last child of their parent.

$('root elem1:last-child');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top