Don't over-skip. #4013.

The contents-reading change that was introduced in f55746c switched
from using `inner_xml` to directly reading text nodes. This made the
code which advanced to then closing element for a variable sometimes
skip the next element. (Specifically, it would skip the next if there
was no text node in the originally focused variable element.)

This change fixes this by checking if we're already at the end element
before attempting to advance to the end element.