 <p>Your order appears to be alphabetical, but since you didn't say this, I'm assuming this isn't a reliable expectation.</p> <p>How's this?</p> <p><a href="http://www.xmlplayground.com/cMOOBF" rel="nofollow">http://www.xmlplayground.com/cMOOBF</a></p> <p>If indeed the order IS is reliably alphabetical, it would be better to first sort your nodes rather than use a complex predicate as I have.</p>