1. A method for rewriting a query that contains a XML query based-expression, the method comprising, performing a first XML rewrite transformation on said query to generate a first inline view that replaces said XML query based-expression, said XML query based-expression being based on a XML query language that supports flow control commands and path expressions, said XML query based-expression including a path expression; after performing said first XML rewrite transformation, performing a first view merge operation on said query to merge said first inline view within said query; after performing said first view merge operation, performing an XML index rewrite on said query to generate a second inline view referencing database objects of an XML index and expressing an evaluation based on said path expression; after performing said XML index rewrite transformation, performing a second view merge operation on said second inline view to merge said second inline view within said query; and wherein the method is performed by one or more computing devices.