Abstract. Research on processing XML documents gained much activity in recent times. XML query languages are mostly based on XPath expressions, which are used to select parts of XML documents. So, methods defining semantics for XPath expressions are of special importance. In the paper we propose a relational semantics for XPath expressions. The semantics consists of four semantic functions defined over specific categories of XPath expressions and over contexts determined by the current state of computation. The definition is all sound, complete and expressive. We show that semantic functions can be naturally encoded in SQL and used to query XML documents stored in relational database. Some relevant optimization problems are also discussed.