aspose file tools*
The moose likes XML and Related Technologies and the fly likes not able to dynamically get the xpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "not able to dynamically get the xpath" Watch "not able to dynamically get the xpath" New topic
Author

not able to dynamically get the xpath

jo sim
Ranch Hand

Joined: Apr 24, 2006
Posts: 37
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%>']">
<xut select="$n/title" />

<xut select="$n/link" />

</x:forEach>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Apr 24, 2006
Posts: 37
yes at runtime. I apologize but what is the way to get the value at runtime?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Apr 24, 2006
Posts: 37
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Apr 24, 2006
Posts: 37
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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.
 
Don't get me started about those stupid light bulbs.
 
subject: not able to dynamically get the xpath