This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes How to use variable for index of element in XPath? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to use variable for index of element in XPath?" Watch "How to use variable for index of element in XPath?" New topic
Author

How to use variable for index of element in XPath?

Nigel Chou
Ranch Hand

Joined: Oct 11, 2001
Posts: 47
This is a question about XSLT. Following XPath returns the 2nd attr_name element under content. Can the index be a variable?

I have tried:


They can not work.

Any idea to help? Thanks.
[ May 24, 2006: Message edited by: Nigel Chou ]

SCJP for Java 2, SCWCD, SCMAD
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Try this:Not sure if it will work any better than your original ideas; from my reading of the XPath Recommendation it looks like your second example should work just as well. Maybe there's something else wrong with it, like your variable doesn't exist or isn't a number or something.
Nigel Chou
Ranch Hand

Joined: Oct 11, 2001
Posts: 47
Originally posted by Paul Clapham:
Try this:Not sure if it will work any better than your original ideas; from my reading of the XPath Recommendation it looks like your second example should work just as well. Maybe there's something else wrong with it, like your variable doesn't exist or isn't a number or something.


Thank you. You are right.
 
Don't get me started about those stupid light bulbs.
 
subject: How to use variable for index of element in XPath?