This might help... http://www.xml.com/pub/a/2000/10/04/transforming/trxml5.html Match on answer/basicinfo[courseid = 'foodcourse'], then do this: <xsl:value-of select="count(../arquements[q1 = 'a1'])"/> See if that works better.