A Core Calculus for Documents