## I have my xml as below and I want get the count of title node I have tried below but I always get count as 1 since it is under for-each loop
<xsl:if test="$countryVal !='' and $countryVal = 'USA'">
<tr>
<td><xsl:value-of select="title"/></td>
<h3>Count of titles <xsl:value-of select="count(catalog/cd/title)"/></h3>
</tr>
</xsl:if>
</xsl:for-each>
<catalog>
<cd>
<title>USD</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>USD</title>
<artist>Bonnie Tyler</artist>
<country>USA</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>CAD</title>
<artist>Dolly Parton</artist>
<country>CAN</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>USD</title>
<artist>Gary Moore</artist>
<country>USA</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
</catalog>
#
xml shared is part of big xml sharing the snippet of it. Any pointers?
<title>nodes in each<cd>, or the number in the whole<catalog>, or something else? If you're looking for the number in the whole catalog, you don't need the<xsl:foreach>; the count will check for all of the results below the<catalog>node.<xsl:value-of select="count(catalog/cd[country='USA']/title)"/>, but this statement would need to go after thexsl:for-each, and not inside it. Note that you could also simplify yourxsl:for-eachto just<xsl:for-each select="catalog/cd[country='USA']">and avoid the need for a variable and if condition inside it.