Consider these 2 expressions:
<company> <employee firstname="John"/> <employee firstname="Peter"/> <employee firstname="Carl"/> </company>
- The 1st expression returns: Peter, Carl
- The 2nd expression returns: John, Peter
to both of those expressions:
- The first sequence is composed of Peter and Carl in that order, and Peter is the employee with context position equal to 1.
- The second sequence is composed of John and Peter in that order, and here Peter, the second employee in the sequence, is the employee with context position equal to 1, not John which is the first employee in the sequence!
preceding-sibling, position is assigned in reverse order. So because a reverse axis is used, the context position of the last item in the sequence is 1. You can think of the engine as assigning context position starting from the node where you start your search: if you are "going down", as with
following-sibling, context positions are assigned in document order, but if you are "going up" like with
preceding-sibling, then context positions are assigned in reverse document order. Even if context positions are assigned differently depending on the type of axis you are using, the nodes returned by a path expression are always in document order. Does this make more sense?