get position after spec. predicate

A

awebguynow

After reviewing posts, I believe that it is impossible, to get, in 1
select statement the position of a xpath with qualifying predicate.
OK, that sounded like jibberish - let me try again.

example: /node[leaf=foo] - get position of node

I think I'll do a for-each instead of trying to be clever, But I will
take suggestions.
 
G

George Bina

Hi,

I do not understand exactly from your example what you are looking
for... The position makes sense if you define a set of nodes and a
reference node, then you can ask for the position of that reference
node in the set. In general if you want to use only XPath to get the
position of a node in a set then you can select the preceding items in
that set and count them. For instance assuming that you have a document
like:

<items>
<item>a</item>
<item>b</item>
<item>c</item>
<item>d</item>
</items>

and you want to get the position of the item with value c in the set of
item elements inside the items root element then you can use an XPath
as below:

count(/items/item[.='c']/preceding-sibling::*) + 1

Hope that helps,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,851
Latest member
CliftonCor

Latest Threads

Top