xpath expression to return the following node

ricky (archive)

Usenet Archive
Joined
Jul 27, 2001
Messages
52
Reaction score
0
I want to return with only one xpath expression the first following node relative to a node with a XPTO attribute.

Example:

<node>
xxx
</node>
<node XPTO="true">
yyy
</node>
<node>
zzz
</node>

i want to return a reference to the node:

<node>
zzz
</node>

thanks in advance
ricky
 

Philippe Poulard

Usenet Archive
Joined
Dec 20, 2001
Messages
412
Reaction score
0
ricky said:
I want to return with only one xpath expression the first following node relative to a node with a XPTO attribute.

Example:

<node>
xxx
</node>
<node XPTO="true">
yyy
</node>
<node>
zzz
</node>

i want to return a reference to the node:

<node>
zzz
</node>

thanks in advance
ricky

hi,

try this :
//node[preceding::node[@XPTO]][1]

what would you expect if there were several nodes with the XPTO attribute ?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
ricky said:
I want to return with only one xpath expression the first following node relative to a node with a XPTO attribute.

Example:

<node>
xxx
</node>
<node XPTO="true">
yyy
</node>
<node>
zzz
</node>

i want to return a reference to the node:

<node>
zzz
</node>

This XPath
//node[@XPTO = 'true']/following-sibling::*[1]
finds the first sibling element node.
 

ricky (archive)

Usenet Archive
Joined
Jul 27, 2001
Messages
52
Reaction score
0
Martin Honnen said:
ricky said:
I want to return with only one xpath expression the first following node relative to a node with a XPTO attribute.

Example:

<node>
xxx
</node>
<node XPTO="true">
yyy
</node>
<node>
zzz
</node>

i want to return a reference to the node:

<node>
zzz
</node>

This XPath
//node[@XPTO = 'true']/following-sibling::*[1]
finds the first sibling element node.

Thanks a lot.
Works perfectly.
I thought that the use of axis were only permitted in the begining of xpath expression. Need to read more Xpath specification :)

Ricky
 

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
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top