Contextual template matching refers to situations where the feature sets of the two templates under consideration may not be identical, but are rather contingent on the context within which these templates are observed. This paper addresses context-dependent template matching where the relevancy of certain features to a given object is contingent on the value of higher level features. In such situations portions of the patterns for two objects X and Y may not be comparable, and therefore classical distance measures are not applicable. A framework for describing pattern spaces with hierarchically dependent features-named conditional pattern spaces (CPS)-is presented, and a distance measure for comparing objects in a CPS is developed and illustrated on archaeological objects. This measure satisfies several desired properties of distance measures, such as the metric requirements.