Bug 22765 - Wrong values from position() and last() functions with forEach
Summary: Wrong values from position() and last() functions with forEach
Status: RESOLVED DUPLICATE of bug 14465
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.0.2
Hardware: Other other
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2003-08-27 16:57 UTC by Asgeir Orn Asgeirsson
Modified: 2010-12-31 18:24 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Asgeir Orn Asgeirsson 2003-08-27 16:57:42 UTC
Consider the following code:

<x:forEach select="$blu/names/name">
    <x:out select="position()"/>. <x:out select="."/>

If the variable $blu stores the following document:

the code above should return:

1. James <br/>
2. Asgeir <br/>

but it returns:

0. James <br/>
0. Asgeir <br/>
Comment 1 Felipe Leme 2003-08-28 03:29:04 UTC
I tested on my environment (JSTL 1.0.3 and Tomcat 4.1.24) and it didn't work
neither. Here is a full jsp test case:

--- start ---
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>

<x:parse var="blu">

<x:forEach select="$blu/names/name">
    <x:out select="position()"/>. <x:out select="."/>

--- end ---

Comment 2 Pierre Delisle 2003-12-13 00:26:34 UTC
Since we moved our XPath support to Xalan, it makes this one harder to fix. I'll
see if our Xalan expert can look into it, but it may have to wait until we
release 1.1 final.
Comment 3 Felipe Leme 2004-05-12 00:27:04 UTC
CC'ing the taglibs-dev address to all Standard bugs. 
Comment 4 Henri Yandell 2006-12-06 17:12:06 UTC
Impressive, in 1.1 this is no longer the case! Now we get:

-1. James
-1. Asgeir 

Progress. When testing in Xalan with the following xsl:

<xsl:template match="names/name">
    <xsl:value-of select="position()"/>. <xsl:value-of select="."/>

I get:

  2. James
  4. Asgeir

Playing around - that's due to whitespace in the xml document counting as elements.
Comment 5 Henri Yandell 2007-03-14 16:53:22 UTC
I've added this to the FAQ:

Otherwise I'm leaving it as is as there is no obvious fix. 
Comment 6 Henri Yandell 2009-11-29 19:46:05 UTC
Also looks like this was a problem with xtags:

Comment 7 Henri Yandell 2009-11-29 19:56:10 UTC
Resolving as wontfix. Not a part of the spec that I would advise relying on.
Comment 8 Jeremy Boynes 2010-12-31 18:21:04 UTC
Fixed with XPath refactoring in r1054175
Comment 9 Jeremy Boynes 2010-12-31 18:24:00 UTC

*** This bug has been marked as a duplicate of bug 14465 ***