We address the problem of query rewriting for TSL, a language for querying semistructured data. We develop and present an algorithm that, given a semistructured query $q$ and a set of semistructured views ${\cal V}$, finds rewriting queries, i.e., queries that access the views and produce the same result as $q$. Our algorithm is based on appropriately generalizing containment mappings, the chase, and query composition -- techniques that were developed for structured, relational data. We also develop an algorithm for equivalence checking of TSL queries. We show that the algorithm is sound and complete for TSL, i.e., it always finds every non-trivial TSL rewriting query of $q$, and we discuss its complexity. We extend the rewriting algorithm to use some forms of structural constraints (such as DTDs) and find more opportunities for query rewriting.