XPath expression that gets a node with 2 particular children

Discussion in 'XML' started by Jeff, Jul 5, 2003.

  1. Jeff

    Jeff Guest

    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.
    Jeff, Jul 5, 2003
    #1
    1. Advertising

  2. > 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" <> wrote in message
    news:...
    > 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.
    Dimitre Novatchev, Jul 5, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:be72s0$1t8o6$...
    > > 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" <> wrote in message
    > news:...
    > > 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.

    >
    >
    Dimitre Novatchev, Jul 5, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,399
  2. Luis Esteban Valencia
    Replies:
    0
    Views:
    366
    Luis Esteban Valencia
    Jun 20, 2005
  3. Alastair Cameron
    Replies:
    1
    Views:
    7,364
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  4. ricky
    Replies:
    3
    Views:
    576
    ricky
    May 13, 2004
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,399
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page