Abstract. In this paper we introduce an approach that allows to handle the containment problem for the fragment XP(/,//,[ ], * ) of XPath. Using rewriting techniques we define a necessary and sufficient condition for pattern containment. This rewrite view is then adapted to query evaluation on XML documents, and remains valid even if the documents are given in a compressed form, as dags.