probably Joomla uses trick with PHP output buffering - this allows to get HTML into PHP variable instead of simply returning it to web browser, modify content of this variable (ie. replace these jdoc statements) and at the end send modified contents to browser. Look ad PHP documentation and ob_start(), ob_clean(), ob_get_contents() etc.