Forum Moderators: phranque
But if I have a repetitive process on a particular subnode, does anyone know if it's indeed more efficient to go relative to that node versus specifying the whole path again:
at the Context node: /Society/Beings
Person
vs
/Society/Beings/Person
btw: Please correct my misuse of terminology.
thanks!
The //Person["Bob"] selector is slower because of the //, not because of the Person["Bob"]-- the parser must scan the entire XML document for all instances of Person, then locate the Bobs. It will look for /Society/Person and /Society/Entities/Person and /Society/Language/Grammar/Person. On the other hand, given /Society/Beings/Person["Bob"] it will jump immediately to the specific case of Person being inside Beings, and then find Bob.
If you are already "inside" /Society/Beings, however, and recursively processing all Persons, there is no need to go back to /Society unless you are also doing processing on /Society/Entities/Persons and need to be explicit about which set you're using at the moment.
Huge speed gains can be made by re-structuring your XML, before you even consider your XSLT...
What may be faster on one implementation may or may not give you an equivalent gain on other implementations.
Ahh, that's why they call you the Dr. Good point-- this particular implementation is in jscript, clientside, something like this:
// original xpath:
var node = dom.selectNodes('/Society/Beings');// then subsequent calls would go from node itself:
var sub = node[i].selectSingleNode('Person["+str+"]);
Anyhow, it was just a theoretical question that struck my curiosity-- in the given example, it is obvious which of the three xpath styles to use; I was just curious if someone had any hard evidence to support that the xml engine (MSXML2.DomDocument in my case) indeed maintains reference to a particular node thereby making it intrinsically faster to go relative to an already selected node, if if the pointer is in fact to the "xpath" again..
eh. I guess I got lonely in our 4-man development staff yesterday! :)