I'm stumped - I'd like to solve this problem using XPath if possible, as it will simplify some supporting Java code. I have a document structured as follows:
<table>
<row id="a">
<data-point value="0">5</data-point>
<data-point value="15">4</data-point>
<data-point value="30">2</data-point>
<data-point value="45">0</data-point>
</row>
<row id="b">
<data-point value="0">8</data-point>
<data-point value="10">6</data-point>
<data-point value="20">4</data-point>
<data-point value="30">0</data-point>
</row>
</table>
The selection is based on an input value. For example, if the inputValue = 17, I need to select the data-points that bracket that value - in this case, select data-points where value="15" and "30". Similarly, if the value is 32, select data-points "30" and "45".
In the event that the number exactly matches one of the data points, it is ok to either return just the matched datapoint, or that datapoint and the next OR previous one (it doesn't really matter so long as the matching datapoint is returned. So, if the inputValue is 15, it is ok to select data-points with value of "15" and "30", "0" and "15", or just "15".
The XPath must also take into account the selector for the row element
I've tried lots of combinations using following-sibbling, last(), etc, but I can't seem to hone in on a suitable XPath. Any gurus out there who can come up with a good XPath?
The following solution gets close but still fails on several cases. The following XPath assumes that the input selection is for row id="a" and an inputValue of 20:
/table/row[@id='a']/data-point[(20 >= number(@value) or 20 <= number(@value)) and following-sibling::*[1]/@value > 20]
a) and 10-20 (from rowb) be returned?