Optimized Translation of XPath into Algebraic Expressions Parameterized by Programs Containing Navigational Primitives