You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Peter Giesin <pg...@hubcitymedia.com> on 2003/03/21 01:04:36 UTC

Dynamic XPath Expression in JSTL

I am trying, without success, to determine if it is possible to use a
variable to specify the XPath expression in the JTSL X taglibs.

For example:

<c:set var="foo" value="/a/b[1]"/>
<x:parse  xml="some-xml-source" var="xml"/>
<x:out select="$xml/a/b[1]"/>

I would like to define the "x:out" statement to use the foo variable
instead of the hard-coded xpath. Something like this: <x:out
select="$xml/$foo"/>

I have read through the spec and various other docs, but just cannot seem 
to get this working. If some one could help point me in the right
direction I would greatly appreciate it.

Thanks.

---
Peter Giesin
Hub City Media, Inc
pgiesin@hubcitymedia.com
Office: (215) 781-1548
Mobile: (917) 710-2552



------------------------------------------------------------------
Jumping through hoops to get E-mail on the road? 
You've got two choices: Join the circus, or use Molly Mail.

Molly Mail -- http://www.mollymail.com
------------------------------------------------------------------
Having trouble sending email from different locations ?
Need a single outgoing mail server that will work from anywhere ?

Set it to smtp.com and never have to change it again !

http://www.smtp.com
------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: Dynamic XPath Expression in JSTL

Posted by Shawn Bayern <ba...@essentially.net>.
On Thu, 20 Mar 2003, Peter Giesin wrote:

> <c:set var="foo" value="/a/b[1]"/>
> <x:parse  xml="some-xml-source" var="xml"/>
> <x:out select="$xml/a/b[1]"/>
> 
> I would like to define the "x:out" statement to use the foo variable
> instead of the hard-coded xpath. Something like this: <x:out
> select="$xml/$foo"/>
> 
> I have read through the spec and various other docs, but just cannot
> seem to get this working. If some one could help point me in the right
> direction I would greatly appreciate it.

You can use XPath variables in XPath expressions within JSTL tags, but the
syntax you're using isn't right.  A variable evaluates to a value; it does
not get string-interpolated into the text of your message.  The expression
you're looking for wouldn't be "$xml/$foo" but "$xml/*[name()=$foo]" or
something similar.

Shawn


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org