How to count filtered itens in xslt
843834Feb 19 2004 — edited Feb 19 2004I'd like to enumerate a list of itens that are filtered by an if clause. The problem is that when using <xsl:value-of select="position()"/> it take in account all the itens, not the filtered ones.
Here's the example (simpler but has the same problem). It filters just the males from a users list:
XML file:
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="users.xsl"?>
<users>
<user name =" Joseph" sex =" Male"/>
<user name =" Bart" sex =" Male"/>
<user name =" Mary" sex =" Female"/>
<user name =" Brenda" sex =" Female"/>
<user name =" Steve" sex =" Male"/>
</users>
XSLT File:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="html"/>
<xsl:template match="users">
<html>
<head>
<title>Male Users </title>
</head>
<body>
<xsl:for-each select="user">
<xsl:if test="@sex = 'Male'">
<xsl:value-of select="position()"/>) <xsl:value-of select="@name"/>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Result I've got:
1) Joseph
2) Bart
5) Steve
Result I need:
1) Joseph
2) Bart
3) Steve
Does any one could tell me a way to get this result???