XSL count number of nodes with parameter



I have the following xml :



<pax>
<age>5</age>
</pax>
<pax>
<age>5</age>
</pax>
<pax>
<age>12</age>
</pax>


And the follwoing xslt:



<xsl:for-each select="paxes/pax">
<xsl:variable name="PaxAge" select="age"/>
<COUNT>
<xsl:value-of select='count(paxes/pax/age[text()=$PaxAge])'/>
</COUNT>
</xsl:for-each>


However the result I get in count is always



<COUNT>1</COUNT>
<COUNT>1</COUNT>
<COUNT>1</COUNT>


If I change it to



<xsl:value-of select='count(paxes/pax/age[text()="5"])'/>


I will receive



<COUNT>2</COUNT>
<COUNT>2</COUNT>
<COUNT>2</COUNT>


How can I get the write count for each iterate?


No comments:

Post a Comment