Move var in fix for #6410

Actually, spocke, did you intend to put the var higher up in the function? The rng object gets replaced in Line 817/818 by the expandRng invocation, which I think returns a new object that omits the commonAncestorContainer.