You can store the <chapter> in a variable and cou
nt like below:
Code:
<xsl:template match="/">
<book>
<xsl:variable name="detail">
<xsl:for-each select="header/detail">
<chapter/>
</xsl:for-each>
</xsl:variable>
<count><xsl:value-of select="count($detail//chapter)"/></count>
</book>
</xsl:template>
If you could post a relevant part of your input xml and xslt, then someone here can give you a good idea.