//b[1]//c gives different results if the first b is nested in anotherelement

Discussion in 'XML' started by yawnmoth, Sep 14, 2008.

  1. yawnmoth

    yawnmoth Guest

    <a>
    <b>
    <c/><c/>
    </b>
    <b>
    <c/><c/><c/>
    </b>
    <b>
    <c/>
    </b>
    </a>

    Doing //b[1]//c on that yields two items. If, however, I put the
    first <b></b> within a <d></d>, I get five items. My question is...
    why?

    Here's what I mean by "put the first <b></b> within a <d></d>":

    <a>
    <d>
    <b>
    <c/><c/>
    </b>
    </d>
    <b>
    <c/><c/><c/>
    </b>
    <b>
    <c/>
    </b>
    </a>

    Why does that return 5 items when the first only returns 2?
    yawnmoth, Sep 14, 2008
    #1
    1. Advertising

  2. Re: //b[1]//c gives different results if the first b is nested inanother element

    yawnmoth wrote:
    > <a>
    > <b>
    > <c/><c/>
    > </b>
    > <b>
    > <c/><c/><c/>
    > </b>
    > <b>
    > <c/>
    > </b>
    > </a>
    >
    > Doing //b[1]//c on that yields two items. If, however, I put the
    > first <b></b> within a <d></d>, I get five items. My question is...
    > why?
    >
    > Here's what I mean by "put the first <b></b> within a <d></d>":
    >
    > <a>
    > <d>
    > <b>
    > <c/><c/>
    > </b>
    > </d>
    > <b>
    > <c/><c/><c/>
    > </b>
    > <b>
    > <c/>
    > </b>
    > </a>
    >
    > Why does that return 5 items when the first only returns 2?



    //b[1] means select all b that are the first b child of their parent.
    If you want to select the first b descendant use
    /descendant::b[1]

    David


    --
    http://dpcarlisle.blogspot.com
    David Carlisle, Sep 14, 2008
    #2
    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. Christian Seberino
    Replies:
    3
    Views:
    1,178
    Christian Seberino
    Feb 5, 2004
  2. Qiangning Hong
    Replies:
    12
    Views:
    698
    Grant Edwards
    Jul 12, 2006
  3. Kerry, Richard
    Replies:
    2
    Views:
    400
    Piet van Oostrum
    Jul 13, 2006
  4. =?Utf-8?B?RmFlc3NsZXIgR2lsbGVz?=

    WepApp - DateTime.Now.Date.ToString() gives different results

    =?Utf-8?B?RmFlc3NsZXIgR2lsbGVz?=, Jun 8, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    8,114
    =?Utf-8?B?RmFlc3NsZXIgR2lsbGVz?=
    Jun 8, 2007
  5. myx
    Replies:
    2
    Views:
    897
Loading...

Share This Page