XPath performance -which one is better? -


i have question concerning performance issues when using xpath.

which 1 better , why? (in case of performance of course):

//a/b/c[@id="x"]/../.. 

vs.

//a[b/c[@id="x"]]  

if anything, you'll hit on performance using // ... processor not going optimize such expression , waste time looking a elements descendent of c elements because asking to. highlight in classroom 1 of common sources of poor performance in xslt processing (and cringe every time see being abused in stackoverflow questions, spend day talking because used often).

as difference between a/b/c[@id='x']/../.. , a[b/c[@id="x"]], depends if processor rewrites former latter part of optimization (since declarative).

if no such optimization happens, former slower latter because former asking processor take time collect c elements , walk backup tree unioning grandparent element of each one. whereas latter expression uses predicate boolean true()/false() test of data-type node set, , processor knows boolean value returned true() @ first detection of such c element , doesn't need other c elements (and shouldn't looking other c elements).


Comments