We study the analysis problem of XPath expressions with counting constraints. Such expressions are commonly used in document transformations or programs in which they select portions of documents subject to transformations. We explore how recent results on the static analysis of navigational aspects of XPath can be extended to counting constraints. The static analysis of this combined XPath fragment allows to detect bugs in transformations and to perform many kinds of optimizations of document transformations. More precisely, we study how a logic for finite trees capable of expressing upward and downward recursive navigation, can be equipped with a counting operator along regular path expressions. Categories and Subject Descriptors H.2.3 [Database Management]: Languages—Query Languages; F.4.1 [Mathematical Logic and Formal Languages]: Mathematical Logic—modal logic General Terms Algorithms, Languages, Theory, Verification Keywords XML, XPath, Type Checking, Counting Constraints,...