get position after spec. predicate

Discussion in 'XML' started by awebguynow, Jan 27, 2006.

  1. awebguynow

    awebguynow Guest

    After reviewing posts, I believe that it is impossible, to get, in 1
    select statement the position of a xpath with qualifying predicate.
    OK, that sounded like jibberish - let me try again.

    example: /node[leaf=foo] - get position of node

    I think I'll do a for-each instead of trying to be clever, But I will
    take suggestions.
     
    awebguynow, Jan 27, 2006
    #1
    1. Advertising

  2. awebguynow

    George Bina Guest

    Hi,

    I do not understand exactly from your example what you are looking
    for... The position makes sense if you define a set of nodes and a
    reference node, then you can ask for the position of that reference
    node in the set. In general if you want to use only XPath to get the
    position of a node in a set then you can select the preceding items in
    that set and count them. For instance assuming that you have a document
    like:

    <items>
    <item>a</item>
    <item>b</item>
    <item>c</item>
    <item>d</item>
    </items>

    and you want to get the position of the item with value c in the set of
    item elements inside the items root element then you can use an XPath
    as below:

    count(/items/item[.='c']/preceding-sibling::*) + 1

    Hope that helps,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
     
    George Bina, Jan 27, 2006
    #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. Ron de Waard
    Replies:
    2
    Views:
    12,619
    HansDampf
    Oct 5, 2007
  2. Drew Volpe
    Replies:
    0
    Views:
    365
    Drew Volpe
    Nov 25, 2003
  3. Jacques

    Predicate by attribute?

    Jacques, Jun 24, 2004, in forum: XML
    Replies:
    2
    Views:
    381
    Jacques
    Jun 24, 2004
  4. Sabba
    Replies:
    0
    Views:
    636
    Sabba
    May 9, 2006
  5. Andrew Chen
    Replies:
    1
    Views:
    206
    David Chelimsky
    Mar 25, 2008
Loading...

Share This Page