see: http://www.ethicalhacker.net/content/view/185/24/
All injection attacks (including html/javascript injection, sql injection, hql injection) pretty much follow the same principles - basically anywhere you are concatenating user input to a command text, you have the potential for an injection attack.
Besides validating the input as mentioned in the above article, another approach (which might be preferred since it safely allows the use of any characters) would be to encode any user input before using it in an xpath.
Update:
At least some Xpath libraries provide for declaring variables to allow safely evaluating user provided input for the xpath expression.
See: