Reworked XPath to be more sensible, given apparently buggy behaviour of fn:matches.