how to find elements that don't have ancestor

Discussion in 'XML' started by kishjeff, Oct 10, 2008.

  1. kishjeff

    kishjeff Guest

    Hi.

    Can someone tell me how to find all the elements of type 'table' which
    have an attribute named 'source' and are not descendents of
    'querybox' ?

    I'm sort of wrestling with it and am hoping someone can tell me if it
    is possible.

    I know it is possible to find all elements that ARE descendents of
    'querybox' that have a given attribute and are of a certain type.

    Jeff
     
    kishjeff, Oct 10, 2008
    #1
    1. Advertising

  2. kishjeff

    kishjeff Guest

    On Oct 10, 2:17 pm, kishjeff <> wrote:
    > Hi.
    >
    > Can someone tell me how to find all the elements of type 'table' which
    > have an attribute named 'source' and are not descendents of
    > 'querybox' ?
    >
    > I'm sort of wrestling with it and am hoping someone can tell me if it
    > is possible.
    >
    > I know it is possible to find all elements that ARE descendents of
    > 'querybox' that have a given attribute and are of a certain type.
    >
    > Jeff


    oh geez, I'm trying out xpath. sorry.. I forgot to mention that
    insignificant item.
     
    kishjeff, Oct 10, 2008
    #2
    1. Advertising

  3. kishjeff

    Peyo Guest

    kishjeff a écrit :

    >> Can someone tell me how to find all the elements of type 'table' which
    >> have an attribute named 'source' and are not descendents of
    >> 'querybox' ?


    > oh geez, I'm trying out xpath. sorry.. I forgot to mention that
    > insignificant item.


    Why not :
    //table[@source and (count(ancestor::querybox) = 0)]

    Cheers,

    p.
     
    Peyo, Oct 10, 2008
    #3
  4. kishjeff

    kishjeff Guest

    On Oct 10, 4:02 pm, Peyo <> wrote:
    > kishjeff a écrit :
    >
    > >> Can someone tell me how to find all the elements of type 'table' which
    > >> have an attribute named 'source' and are not descendents of
    > >> 'querybox' ?

    > > oh geez, I'm trying out xpath. sorry.. I forgot to mention that
    > > insignificant item.

    >
    > Why not :
    > //table[@source and (count(ancestor::querybox) = 0)]
    >
    > Cheers,
    >
    > p.


    thanks so much. that works just fine evidently. is there a way of
    doing it without count, say with some sort of "not
    decendent::querybox" sort of thing?

    regards in any case
    Jeff
     
    kishjeff, Oct 11, 2008
    #4
  5. kishjeff

    Peyo Guest

    kishjeff a écrit :

    > thanks so much. that works just fine evidently.


    You did most of the work ;-)

    < is there a way of
    > doing it without count, say with some sort of "not
    > decendent::querybox" sort of thing?


    Just try not(descendant::querybox)

    not() is a *function*, hence the parentheses.

    XPath 2.0 also introduces some other functions like exists().

    Be aware that not(descendant::querybox) it is not what you have asked :)

    Cheers,

    p.b.
     
    Peyo, Oct 11, 2008
    #5
  6. kishjeff

    Peter Flynn Guest

    kishjeff wrote:
    > On Oct 10, 4:02 pm, Peyo <> wrote:
    >> kishjeff a écrit :
    >>
    >>>> Can someone tell me how to find all the elements of type 'table' which
    >>>> have an attribute named 'source' and are not descendents of
    >>>> 'querybox' ?
    >>> oh geez, I'm trying out xpath. sorry.. I forgot to mention that
    >>> insignificant item.

    >> Why not :
    >> //table[@source and (count(ancestor::querybox) = 0)]
    >>
    >> Cheers,
    >>
    >> p.

    >
    > thanks so much. that works just fine evidently. is there a way of
    > doing it without count, say with some sort of "not
    > decendent::querybox" sort of thing?
    >
    > regards in any case
    > Jeff


    //table[@source and not(ancestor::querybox)]

    ///Peter
     
    Peter Flynn, Oct 11, 2008
    #6
  7. kishjeff

    Jeff Kish Guest

    On Sat, 11 Oct 2008 14:31:08 +0100, Peter Flynn
    <> wrote:

    >kishjeff wrote:
    >> On Oct 10, 4:02 pm, Peyo <> wrote:
    >>> kishjeff a écrit :
    >>>
    >>>>> Can someone tell me how to find all the elements of type 'table' which
    >>>>> have an attribute named 'source' and are not descendents of
    >>>>> 'querybox' ?
    >>>> oh geez, I'm trying out xpath. sorry.. I forgot to mention that
    >>>> insignificant item.
    >>> Why not :
    >>> //table[@source and (count(ancestor::querybox) = 0)]
    >>>
    >>> Cheers,
    >>>
    >>> p.

    >>
    >> thanks so much. that works just fine evidently. is there a way of
    >> doing it without count, say with some sort of "not
    >> decendent::querybox" sort of thing?
    >>
    >> regards in any case
    >> Jeff

    >
    >//table[@source and not(ancestor::querybox)]
    >
    >///Peter

    ah its so easy... thanks.
     
    Jeff Kish, Oct 12, 2008
    #7
    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. Johnny
    Replies:
    0
    Views:
    898
    Johnny
    Oct 2, 2003
  2. Replies:
    0
    Views:
    343
  3. Ognen Ivanovski
    Replies:
    0
    Views:
    946
    Ognen Ivanovski
    Jul 15, 2003
  4. Eshrath
    Replies:
    3
    Views:
    3,912
    Morris M. Keesan
    Oct 27, 2004
  5. Ilmari Heikkinen
    Replies:
    0
    Views:
    98
    Ilmari Heikkinen
    Jan 17, 2005
Loading...

Share This Page