XPath expression that gets a node with 2 particular children

J

Jeff

I'd like to write an XPath expression that gets a node with 2
particular children.

I thought this would work:
/AAA/BBB/CCC/following-silbing::DDD/parent::node()

on xml like this:

AAA
BBB
CCC
DDD
/BBB
/AAA

But it doesn;t seem to. I've been testing it here:
http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/source1.html
I would like to have some sort of "/sibling::DDD" so that I can find
any sib not just following or preceeding, but I can't seem to find a
way to do that either.

Any ideas?

BTW, My next step is to also require the that a particular attribute
of one of the children has one of a set of values.

Thanks.
 
D

Dimitre Novatchev

In case the order of the children matters, then this should be reflected in
the XPath expression:

/AAA/BBB[ *[1][self::CCC] and *[2][self::DDD] and not(*[3]) ]



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



Dimitre Novatchev said:
AAA
BBB
CCC
DDD
/BBB
/AAA

This is not xml at all, probably you meant:


<AAA>
<BBB>
<CCC/>
<DDD/>
</BBB>
</AAA>



Use:

/AAA/BBB[CCC and DDD and not(*[3])]




=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




Jeff said:
I'd like to write an XPath expression that gets a node with 2
particular children.

I thought this would work:
/AAA/BBB/CCC/following-silbing::DDD/parent::node()

on xml like this:

AAA
BBB
CCC
DDD
/BBB
/AAA

But it doesn;t seem to. I've been testing it here:
http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/source1.html
I would like to have some sort of "/sibling::DDD" so that I can find
any sib not just following or preceeding, but I can't seem to find a
way to do that either.

Any ideas?

BTW, My next step is to also require the that a particular attribute
of one of the children has one of a set of values.

Thanks.
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top