Skip to main content

developerWorks >  XML  >  Forums  >  XQuery and XPath forum  >  developerWorks

How can I use a variable for the xpath position()    Point your RSS reader here for a feed of the latest messages in this thread


Tags for this thread: 

     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is not answered.

Permlink Replies: 2 - Pages: 1 - Last Post: Nov 4, 2009 10:23 AM Last Post By: tsuji
stormgutz

Posts: 2
Registered: Nov 03, 2009 04:04:54 PM
How can I use a variable for the xpath position()
Posted: Nov 03, 2009 04:12:12 PM
 
Click to report abuse...   Click to reply to this thread Reply
I would like to be able to use a variable to contain the number of the child I am looking for.

so for instance
I have used "//Featposition() = 4 "

I would like to be able to do something like:
"//Featposition() = myVar "

where I can assign the value to the myVar variable to be able to provide direct access to a particular node.
stormgutz

Posts: 2
Registered: Nov 03, 2009 04:04:54 PM
Re: How can I use a variable for the xpath position()
Posted: Nov 03, 2009 04:16:37 PM   in response to: stormgutz in response to: stormgutz's post
 
Click to report abuse...   Click to reply to this thread Reply
sorry in the above example I didn't escape the brackets
the current code is
//Feat[position() = 4 ]


and the desired code would be
//Feat[position() = myVar ]


where I can change the value of the myVar to allow direct access to the node
tsuji

Posts: 28
Registered: Sep 14, 2009 12:58:36 PM
Re: How can I use a variable for the xpath position()
Posted: Nov 04, 2009 10:23:19 AM   in response to: stormgutz in response to: stormgutz's post
 
Click to report abuse...   Click to reply to this thread Reply
For instance, in xslt, it would look like this, supposing getting the text of it.
<xsl:variable="myVar" select="4" />
<xsl:value-of select="//Feat[position()=$myVar]" />

But you might be thinking in other technologies, such as xquery... The xpath bit would still be the same.
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums