For another question I have created some XML related code that works on my development machine but not on viper codepad where I tested it before adding it to my answer.
XPath is a query language, thus it should only read the structure of the .xml document as is and never modify it. This includes the node order. In your first example however this is not true. So this is definitely a bug according to this.