Position of a node

Discussion in 'XML' started by Hans-Michael Rupp, Jul 9, 2003.

  1. Hallo!

    How can find out the postion of a node with a particular content in the
    nodeset WITHOUT being in the context?

    I would like have something like
    <xsl:variable name="position" select="position(/foo/bar[blubber='test'])">
    of course position() does not work this way.

    Is there another way to solve this?

    Many thanks,

    Hans
    Hans-Michael Rupp, Jul 9, 2003
    #1
    1. Advertising

  2. Hans-Michael Rupp

    Marrow Guest

    Hi Hans,

    Depends on what you are actually trying to accomplish?

    Crudely...

    > <xsl:variable name="position" select="position(/foo/bar[blubber='test'])">


    Do you want the 'position' of <bar> within all children of the <foo>
    element? e.g.
    <xsl:variable name="position"
    select="count(/foo/bar[blubber='test']/preceding-sibling::*)"/>

    Do you want the 'position' of <bar> within all <bar> element children of the
    <foo> element? e.g.
    <xsl:variable name="position"
    select="count(/foo/bar[blubber='test']/preceding-sibling::bar)"/>

    etc. etc.

    But you may get very unexpected results from the above unless the node you
    are starting at (i.e. the part of the expression before the
    /preceding-sibling axis) is gauranteed to be a single node.

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "Hans-Michael Rupp" <> wrote in message
    news:...
    > Hallo!
    >
    > How can find out the postion of a node with a particular content in the
    > nodeset WITHOUT being in the context?
    >
    > I would like have something like
    > <xsl:variable name="position" select="position(/foo/bar[blubber='test'])">
    > of course position() does not work this way.
    >
    > Is there another way to solve this?
    >
    > Many thanks,
    >
    > Hans
    >
    Marrow, Jul 9, 2003
    #2
    1. Advertising

  3. The position of *which* node in *what* nodeset?

    You haven't specified either.


    Also, the XPath position() function is defined on the current *node-list*,
    not node-set. This means that position() can be used:

    in a relation in predicates within an XPath expression to select nodes
    whose position in the current node-list satisfies this relation,

    or

    in the body of xsl:for-each or of xsl:template to return the position of
    the current node in the current node-list.



    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL



    "Hans-Michael Rupp" <> wrote in message
    news:...
    > Hallo!
    >
    > How can find out the postion of a node with a particular content in the
    > nodeset WITHOUT being in the context?
    >
    > I would like have something like
    > <xsl:variable name="position" select="position(/foo/bar[blubber='test'])">
    > of course position() does not work this way.
    >
    > Is there another way to solve this?
    >
    > Many thanks,
    >
    > Hans
    >
    Dimitre Novatchev, Jul 9, 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. wolf
    Replies:
    0
    Views:
    546
  2. Replies:
    0
    Views:
    1,414
  3. Replies:
    0
    Views:
    365
  4. Eddy C
    Replies:
    6
    Views:
    6,402
    Eddy C
    Oct 18, 2005
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,406
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page