The OR operator scores the higher of its two sides, so this will work in most situations. However there is an edge-case where it won't - if "X within B" scores less than half of "X within A" then the score of the second part will become just that for "X within A" (because AND scores the lower of its two sides) and therefore X within B will not add to the overall score.
SELECT * FROM foo WHERE CONTAINS( xml, '(X within A) OR ( (X within A) AND (X within B) )*2' , 1)
Will always work. ACCUM guarantees that hits on both sides always score higher than hits on one side only, and the right-hand side here subsumes the left-hand side.
SELECT * FROM foo WHERE CONTAINS( xml, '(X within A) ACCUM ( (X within A) AND (X within B) )' , 1)