: We present a grammar-based approach to specifying k-ary queries for XML documents. k-ary queries simultaneously locate k nodes of an input tree as specified by a given relation. In practice, we are interested in unary and binary queries, as classes of queries for which efficient implementations exist. The grammar-based approach is used as basis for the fxgrep query language, on top of which the fxt transformation language is built. Using fxt as an example, we present how binary queries can be used to support more efficient and declarative XML transformations.