position() is the 1-based index of the position of the current
context node within the current context.

given:

        <foo>

                <bar id="1">

                <baz id="2">

                <bar id="3">

        </foo>

The position() of <bar id="3"> with the path /foo/bar is 2.

The easiest way to understand position() is to understand proximity
predicates.  

        /foo/bar[2]  

is equiv to

        /foo/bar[position() = 2]

position() is only relative to the current step of the location path,
and isn't a document-wide position indicator.

Though, in your case of //someelement[@id='S55'], I would've guessed
that position() would return 1, at least, since if you did find a unique
element, it's inherently the 1st element of the current context.

        -bob

On Tue, 19 Mar 2002, Mark Hortman wrote:

> 
> Can someone help a xpath newbie figure out a simple xpath expression?
> 
> Upon learning that //someelement does not guarantee the order that things
> come back in are document order, I have switched tacts and decided to try to
> handle it my self.  I was thinking about playing around with the position()
> function, but cannot get Jaxen to return the position of an element to me.
> 
> I have tried 
> //someelement[@id='S55']/position()  but that returns 0 in all cases
> 
> How can I determine the document order position of an element without
> walking the whole tree in JDOM?  
> 
> Any ideas?
> 
> _______________________________________________
> Jaxen-interest mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jaxen-interest
> 


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to