protected function chooseContext(\Closure $fn) { // If the user has requested ['root' => null] at construction time // 'context()' promotes DOMDocument as root node. $context = $this->context(); $new_context = $fn($context); if ($context !== $new_context) { // If the two contextes are diffent, the user has requested // a switch of the context and we have to return it. return $new_context; } return $this; }