Bug 47681 - count function returning incorrect results
Summary: count function returning incorrect results
Alias: None
Product: Taglibs
Classification: Unclassified
Component: XTags Taglib (show other bugs)
Version: 1.1.0
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2009-08-11 13:24 UTC by Jay S
Modified: 2009-11-29 19:48 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Jay S 2009-08-11 13:24:21 UTC

I am having an issue with using the count function to count the number of entries in an XML document.  

For example, given the JSP text:
<%@ taglib uri ="http://java.sun.com/jsp/jstl/core" prefix ="c"%>
<%@ taglib uri ="http://java.sun.com/jsp/jstl/xml" prefix ="x"%>

<x:parse var="doc" xml="<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><world><country><id>1</id><name>Canada</name></country><country><id>2</id><name>USA</name></country></world>" /> 

<x:out select="count($doc/world/country)"/>  
<x:out select="count($doc/country)"/>


will result in the count($doc/world/country) always returns 0 (zero)
but the count($doc/country) will return 2.

Is this a bug?  I have tried debugging the taglib code but I cannot figure out what is going wrong.

Comment 1 Jay S 2009-08-12 06:31:27 UTC
Just an addition to my original post.  
The "count($doc/world/country)" call will return zero (I think it should return 2.  But when you put the $doc/world/country in a x:forEach tag it will behave correctly and result in two iterations...like this:

<x:forEach select="$doc/world/country" var="test">
   found a country<br>

This will result in "found a country<br>" being printed out twice..which is expected. 

It seems that once the expression is wrapped in the count function it is not handled properly.  

I noticed in the XPathUtil.adaptParamsForXalan method is only checking if the xpath variable starts with a '$' in order to create the appropriate Node and resolve the variable.  In the case of the count($doc/world/country) expression this does not start with a '$' and will result in the method creating a DummyDocument instead of resolving the variable appropriately.  

Comment 2 Mark Thomas 2009-08-17 01:55:54 UTC
Update assignee to Tomcat dev list
Comment 3 Henri Yandell 2009-11-29 19:48:33 UTC
Resolving. Taglib has been retired.