Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 15757 invoked by uid 98); 15 Jan 2003 19:32:21 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 15705 invoked from network); 15 Jan 2003 19:32:19 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 15 Jan 2003 19:32:19 -0000 Received: (qmail 66251 invoked by uid 500); 15 Jan 2003 19:30:55 -0000 Received: (qmail 66243 invoked from network); 15 Jan 2003 19:30:55 -0000 Received: from atlsmtp.jacada.com (12.166.230.15) by daedalus.apache.org with SMTP; 15 Jan 2003 19:30:55 -0000 Subject: Re: [JXPath] Problem with maps and variables To: "Jakarta Commons Users List" X-Mailer: Lotus Notes Release 5.0.8 June 18, 2001 Message-ID: From: "Steve Pannier" Date: Wed, 15 Jan 2003 13:35:13 -0600 X-MIMETrack: Serialize by Router on Jacada_Atl_Smtp/CST(Release 5.0.8 |June 18, 2001) at 01/15/2003 02:23:09 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Dmitri, Thanks for the tip. It works! Our wrapper object's toString() method does indeed return the integer value as a String. So now we use: "$map/dataMap/Foo/Bar[number($map/dataMap/Foo/Count[1])]" Behold, the power of XPath! :) Thanks again for your help. Steve Pannier Jacada, Inc. (763) 201-0002 Ext. 219 spannier@jacada.com http://www.jacada.com > Steve, > > Here's another option: > > "$map/dataMap/Foo/Bar[number($map/dataMap/Foo/Count)]" > > The "number" function will first convert the value to string and then > to number. So, as long as your custom object's toString() method > returns the integer content, this should work. > > - Dmitri > > > --- Steve Pannier wrote: > > > > Dmitri, > > > > Thanks for the reply. This explains a lot of what we've been seeing. > > I tried your suggestion #2 (use "$map/dataMap/Foo/Count[1]" as the > > predicate) with my test program and it works. > > > > Unfortunately, the data in our application is customized so that all > > value > > objects within the map are wrapped inside a custom class. So using > > $map/dataMap/Foo/Count[1] for the predicate will still fail to give > > the > > desired results, since the Integer object it represents is wrapped in > > another class. (This custom way of storing our data in maps was an > > area of concern for us when we started using XPath.) And, > > unfortunately, > > your suggestion #1 (put a number in the map instead of the list) is > > not > > an option. > > > > I'll have to chew on this for awhile. I'm not sure what we can do, > > other > > than pre-parse the expression and replace "predicates" with their > > true > > integer values before evaluating the expression itself. > > > > Thanks again for clearing this up. > > > > Steve Pannier > > Jacada, Inc. > > (763) 201-0002 Ext. 219 > > spannier@jacada.com > > http://www.jacada.com > > > > > > > Steve, > > > > > > The explanation for the seemingly inconsistent behavior of JXPath > > is > > > quite simple. > > > > > > The value for the key "Count" in your example is not really an > > integer, > > > but a list containing an integer. That makes a difference. > > According > > > to the XPath specification, the predicate (the expression in > > brackets) > > > is used differently for different types. If the value of the > > > expression is a number, it is used as an index. If it is not a > > number, > > > it is converted to a boolean. The nodes for which it evaluates to > > true > > > are included in the resulting collection. In our case the value of > > the > > > expression is a non-empty list, so it evaluates to true for every > > > element of the collection. This is why every element is included in > > the > > > resulting list. > > > > > > There are two solutions to the problem: > > > > > > 1. Put a number in the map, instead of a list > > > 2. Change the xpath like this: > > > "$map/dataMap/Foo/Bar[$map/dataMap/Foo/Count[1]]". > > > > > > I hope this helps. > > > > > > - Dmitri > > > > > > > > > > > -- > > To unsubscribe, e-mail: > > > > For additional commands, e-mail: > > > > > > > __________________________________________________ > Do you Yahoo!? > Yahoo! Mail Plus - Powerful. Affordable. Sign up now. > http://mailplus.yahoo.com > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > >