Improved TemplateOptimizer::minifyXPath()