Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Position of Element using xpath

    Hello

    this is my xml-structure:
    Code:
    <AAA>
         <BBB>
              <CCC id="h" />
              <CCC id="f" />
         </BBB>
         <BBB>
              <CCC id="o" />
              <CCC id="i" />
              <CCC id="x" />
         </BBB>
         <BBB>
              <CCC id="a" />
         </BBB>
    </AAA>
    for a CCC-Element i want to know the position of the depending BBB node

    ex.: the pos for CCC id="o" is 1 (equals to id="i" and id="x"), for id="a" it's 2

    why gives me this code an empty result-set?
    Code:
    $xpath = '//CCC[@id="o"]/preceding-sibling::*';
    thanks

    Gru▀
    Lena

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    I'd wager it's because BBB isn't a sibling of CCC, but a parent.

    Sorry I can't give you a better answer than that.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by schokoschnute View Post
    Hello

    this is my xml-structure:
    Code:
    <AAA>
         <BBB>
              <CCC id="h" />
              <CCC id="f" />
         </BBB>
         <BBB>
              <CCC id="o" />
              <CCC id="i" />
              <CCC id="x" />
         </BBB>
         <BBB>
              <CCC id="a" />
         </BBB>
    </AAA>
    for a CCC-Element i want to know the position of the depending BBB node

    ex.: the pos for CCC id="o" is 1 (equals to id="i" and id="x"), for id="a" it's 2

    why gives me this code an empty result-set?
    Code:
    $xpath = '//CCC[@id="o"]/preceding-sibling::*';
    thanks

    Gru▀
    Lena
    try to use parent instead of preceding-sibling:

    Code:
    $xpath = '//CCC[@id="o"]/parent::*';
    in my opinion you don't need something more complicated then:

    Code:
    $xpath = '//BBB[CCC/@id="o"]';
    try this, maybe can help:

    http://www.zvon.org:9001/saxon/cgi-b...L/source1.html

    regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •