Let’s say I’m querying an xhtml document, and I want to query all of the siblings following a table with id='target'. Also, I neither want the first <table> sibling nor the first <ol> sibling of this particular element. Here’s the best I could come up with:
//table[@id='target']/following-sibling::*[not(self::table[1]) and not(self::ol[1])]
However, this isn’t returning any results when it should. Obviously I’m not understanding some of the syntax for this (I couldn’t find a good source of information). I would certainly appreciate it if someone more experienced with XPath syntax could give me a hand. Also, for purely academic purposes, I’d be curious what the above is actually doing.
UPDATE:
See LarsH’s answer for the explanation of why my XPath wasn’t working, and see Dimitre’s answer for the accepted solution.
Use:
This selects all the following siblings of the table that are not
tableand are notoland all the followingtablesiblings with position 2 or greater and all the followingolsiblings with position 2 or greater.Which is exactly what you want: all following siblings with the exception of the first
tablefollowing sibling and the firstolfollowing siblings.This is pure XPath 1.0 and not using any XSLT functions.