XML-based databases have become a major area of in database research. Abstractly speaking they can be considered as a resurrection of complexvalue databases using constructors for records, lists, unions plus optionality and references. XQuery has become the standard query language for XML. In this paper an implementation of XQuery based on linguistic reflection is proposed. That is, XQuery is translated into a query algebra for rational tree types based on simple operations and structural recursion for lists. The major purpose of using reflection is to expand path expressions in a type-safe way.