• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

not able to dynamically get the xpath

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi is there a way to find the title and link based on the title provided dynamically?


<% String val="disney"; %>

<c:import url="books.xml" var="url" />
<x:parse xml="${url}" var="doc" />
<x:forEach var="n" select="$doc/books/book[title='<%=val%>']">
<x:out select="$n/title" />

<x:out select="$n/link" />

</x:forEach>
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there is.

But your post title suggests you have already tried something. We should start with that; don't expect anybody to write a magazine article for you about all your possible alternatives complete with links to tutorials.

And by "dynamically" do you mean "at run time"?
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes at runtime. I apologize but what is the way to get the value at runtime?
 
Paul Clapham
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To get what value? Something is missing from your question, I don't see any title and link elements in that XML.

Edit: Okay, I just noticed that what you posted wasn't really XML at all, it was some JSP code that tries to use XPath to get data. So you're saying that doesn't work? Well, have you tried something simpler? Like trying to get the root element? All kinds of things might be going wrong there. Maybe your URL isn't pointing to any XML, for example. Or maybe your method of inserting the title isn't right. Or maybe something else. So start with the simplest possible thing first.
[ October 29, 2008: Message edited by: Paul Clapham ]
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I try to substitute <%=val%> with just disney it works but the thing is I need to get the title and link at runtime by providing a scriplet like <%=val%>
 
Paul Clapham
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So it's the scriptlet part that doesn't work. So don't use a scriptlet. They don't really work well with JSTL. Use a JSTL construct instead.
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so there is no way I can use scriplet in my xpath. can you please give me an example how I should be doing this? I tried doing
<c:set var="Product" value="Product" /> and than I tried
<x:forEach var="n" select="$doc/root/sitemapdetails[sitemaptitle='${Product}']"> but no success
 
Paul Clapham
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you should be debugging. Maybe you don't have the quotes around the value in the XPath expression you're generating. Maybe the quotes you have there prevent the EL from being evaluated. At any rate the simplest way to find out if you're generating the correct XPath expression is to look at the XPath expression that you are generating.
 
reply
    Bookmark Topic Watch Topic
  • New Topic