Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to count filtered itens in xslt

843834Feb 19 2004 — edited Feb 19 2004
I'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???
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2004
Added on Feb 19 2004
1 comment
268 views