Query translation has been a central task for data integration or information sharing. In this paper, we assume that the source and target databases may be XML or relational, with the query languages XQuery and SQL, respectively. Besides, there may exist many possible mappings with different weights between two schemas, which are usually produced by automatic schema matching tools. We intend to output the most preferable query based on weights among all equivalent ones, so we need to properly represent the weighted schema mappings and input queries. Our approach is to first classify the schema representation into two basic units, i.e., collections and values, and apply mapping functions to represent the correspondence for each basic unit with weight information. We then propose a set of tree structures, collectively called CanForest, which show the structural constraints and semantics of the input query and assist in producing the output queries. We have constructed the complete translation system and shown its effectiveness. Experimental results also demonstrate that the system is very efficient.