If you want to do such things, please have a look at the XPath Java library which is included in the CommunityCommons. That way, you can programmatically construct the Xpath and execute it. I would suggest to use the proxy classes instead of building a String.