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

//person[$field[contains(.,$value)]]

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 [mailto:james_strachan@yahoo.co.uk] 
Sent: Friday, July 13, 2001 10:49 AM
To: taglibs-user@jakarta.apache.org
Cc: john.townsend@listenpoint.com
Subject: Re: xtags:ForEach question (involving parameters)

Hi John

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

From: "John Townsend" <john.townsend@listenpoint.com>
> I am having a problem with forEach in the xtags library. I am trying
to
> 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

<directory>
<person>
<name>Foo $param Townsend</name>
</person>
</directory>

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

//person[contains(name,$param)]

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


> 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
could
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
of
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
simple
examples. (I always find learning by example easier than reading specs,
particularly for languages)

http://www.zvon.org/xxl/XPathTutorial/General/examples.html

James




_________________________________________________________

Do You Yahoo!?

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




Mime
View raw message