tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Townsend" <>
Subject RE: xtags:ForEach question (involving parameters)
Date Fri, 13 Jul 2001 19:05:32 GMT
Thanks again for the input.. I appreciate it. I am beginning to think
that maybe building the select statement dynamically in Java code is
probably the way to go.

Thanks for the pointers to XPath wizard and the tutorial. I have looked
at both of them and they have definitely helped. One thing I can't
figure out in either of them: Sorting. 

In the forEach tag, you can pass in an XPath expression for sorting. I
have tried a variety of different expressions in the XPath wizard and it
seems to have no effect on the results. 

What I would like to do is sort all of the person objects that are
returned from the forEach select statement by an attribute (name, phone
number, title, etc.)

Is this something that sorting can handle or do I need to find another

-- John Townsend

-----Original Message-----
From: James Strachan [] 
Sent: Friday, July 13, 2001 12:03 PM
To: John Townsend
Subject: Re: xtags:ForEach question (involving parameters)

Hi John

Yes Bill is right. If you want to build up an XPath expression
you can always do it in Java code before you call the xtags. This can
be much easier if you want to dynamically resolve the elements or
to search for.

>is this legal:
> //person[$field[contains(.,$value)]]

Not quite.

> Where $field and $name would come from the query string? This doesn't
> cause an exception, but it doesn't work either. I just seem to get all
> of the person objects back.

XPath allows variables to be used but mostly for testing either node
equality or string values. For example if $field is the name of an
you wish to test for then the following is valid XPath:-

//person/*[name()=$field and contains(.,$value)]

The above will select all of the immediate child elements of <person>
are called the value of $field and the text of the element contains the

e.g. that would select ..

    <name>John Townsend</name>

The expression would match the <name> element if the query string was

If you actually wanted the person tag then append a /..

//person/*[name()=$field and contains(.,$value)]/..

BTW if you ever want to play around with XPath expressions, there is a
little XPath Wizard JSP in the xtags example web app that might help. Or
this site is useful too, its an online XPath tool from Zvon...



Do You Yahoo!?

Get your free address at

View raw message