In css or jquery this:
#related article
will select all article elements inside the element with the id “related”. When I use this xpath selector:
//descendant-or-self::*[@id = 'related']/descendant::article
It just picks the 1st article element. It doesn’t select the rest that are also in that “related” div. How to select all of them?
Well with XPath (1.0) doing
id('related')//articleor//*[@id = 'related']//articledoes select a node-set ofarticledescendant elements. Even your path//descendant-or-self::*[@id = 'related']/descendant::articledoes not restrict the result to a single element so I suspect the problem is how you look at the XPath result or how you evaluate it. The only way a path itself restricts the result to a single node is by doing e.g.(//*[@id = 'related']//article)[1], with other paths I would check the XPath API whether the method you use (selectSingleNodeor similar?) is the culprit and useselectNodesor similar.