You can use the count XPath expression on the values of the group1: count(../my:group1/Value) However it seems it always return +1 so you should change above expression to: count(../my:group1/Value) - 1