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 18:42:56 GMT
Hi James.. thanks for the response. Here's another question. Is this


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.

BTW.. Thanks again for your message. Its greatly appreciated!

-- John Townsend

-----Original Message-----
From: James Strachan [] 
Sent: Friday, July 13, 2001 10:49 AM
Subject: Re: xtags:ForEach question (involving parameters)

Hi John

(I'm reposting this as my previous post seemed to vanish)

From: "John Townsend" <>
> I am having a problem with forEach in the xtags library. I am trying
> use XPath and xtags to select all of the person entries from my
> directory that contain a substring (For example, all of the people who
> have 'John' in their name).
> I have an XML file that looks basically like this:
> <directory>
> <person>
> <name>John Townsend</name>
> ...more data...
> </person>
> </directory>
> Here's a piece of my JSP page:
> <xtags:forEach select = "//person[child::name[contains(text(),
> '$param')]]">

The $param should not be in quotes. Putting that in quotes means look
for a
name that contains the literal string "$param" such as

<name>Foo $param Townsend</name>

So the XPath expression to evaluate the current param variable that you


I took the liberty of simplifying the XPath syntax a bit. More on that

> If my select in the forEach looks like this:
> Select = "//person[child::name[contains(text(), 'John')]]"
> Then it works.

BTW you can drop the child:: axis as that is the default axis to

//person[name[contains(text(), 'John')]]

Then the contains() function turns both objects into strings so you
simplify that again to

//person[name[contains(., 'John')]]

which is the same as

//person[contains(name, 'John')]

Remember only use '' to denote literal strings, never use it for names
elements, attributes or variables.

> Forgive my ignorance of XPath, I am just starting to use the
> xtags library and XPath.

No problem.

I can highly recommend the Zvon tutorial for XPath, it takes about 10-20
minutes and teaches at least 90% of XPath thats important using some
examples. (I always find learning by example easier than reading specs,
particularly for languages)



Do You Yahoo!?

Get your free address at

View raw message