tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Townsend" <john.towns...@listenpoint.com>
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
way?

Thanks,
-- John Townsend


-----Original Message-----
From: James Strachan [mailto:james_strachan@yahoo.co.uk] 
Sent: Friday, July 13, 2001 12:03 PM
To: John Townsend
Cc: taglibs-user@jakarta.apache.org
Subject: Re: xtags:ForEach question (involving parameters)

Hi John

Yes Bill is right. If you want to build up an XPath expression
dynamically
you can always do it in Java code before you call the xtags. This can
often
be much easier if you want to dynamically resolve the elements or
attributes
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
element
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>
which
are called the value of $field and the text of the element contains the
$value.

e.g. that would select ..

<person>
    <name>John Townsend</name>
</person>

The expression would match the <name> element if the query string was
field=name&value=John

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...

http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/extras.html

James



_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com




Mime
View raw message