tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: xtags:ForEach question (involving parameters)
Date Fri, 13 Jul 2001 19:03:23 GMT
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

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