The expressions last() and position() both return 0 in every iteration of a forEach tag. It is real hard to develop a JSTL app without these expressions working. When will this be fixed? Below is a simple example that will demonstrate the problem: <%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <html> <head> <title>Test</title> </head> <body> <x:parse var="xml"> <?xml version="1.0" encoding="ISO-8859-1"?> <root> <name> <first>James</first> </name> <name> <first>Jose</first> </name> <name> <first>Jen</first> </name> </root> </x:parse> <x:forEach select="$xml/root/name"> <x:out select="first"/> <x:out select="position()"/> </x:forEach> </body> <html> In this example the position() returns '0' every time.
This isn't a bug in the implementation; I believe it requires additional support from the JSTL specification before being implemented. In particular, the following definitions would need to be added: I believe it would involve adding definitions to the spec along the following lines: Inside the body of the <x:forEach> tag, the context for XPath expression evaluations is obtained as follows: * variable, function, and namespace bindings operate as in the rest of JSTL * the context node is the node whose representation would be exposed by 'var' (whether or not the 'var' attribute is specified) * the context position is the iteration 'count' (with the same meaning as in <c:forEach>) * the context size is equal to the number of nodes in the node-set over which <x:forEach> is presently iterating. We're also considering adding varStatus, which would provide an alternative mechanism for achieving the same result. Just because I'm marking this "INVALID" here doesn't mean it's not important; I'm just noting that it's not an implementation issue. (This bug-tracking system is just for implementation issues.)
*** Bug 14687 has been marked as a duplicate of this bug. ***
*** Bug 15483 has been marked as a duplicate of this bug. ***
Fixed with XPath refactoring in r1054175
*** Bug 22765 has been marked as a duplicate of this bug. ***