In my custom module I want to rewrite parts of several .phtml files. For example, in app/design/frontend/base/default/template/bundle/catalog/product/price.phtml, I want to rewrite <div class="price-box">
.
Please note: I do not want to override the entire file, just this one div.
Given that when I override blocks and models I can rewrite individual functions of specific core classes by simply extending the class, I would expect that I could also rewrite a single element of a .phtml file by using SimpleXMLElement::xpath to use xpath to manipulate the XML of the .phtml file itself. That way I could make my module automatically detect if the parts of the .phtml file it's overriding have been changed (say, by an update, or by the installation of another module) and automatically disable my module and warn the user should this occur.
How would I go about approaching doing this? It seems that every guide I can find to how to override a .phtml file takes the rather draconian, brutal, and ugly approach of having a separate folder outside the module's main folder (/app/code/{codePool}/{nameSpace}/{moduleName}), instead putting it into /app/design/frontend/{rest of the path}. This seems very non-ideal because not only does it mean the module is not self-contained in a single directory (for everything but the module's main XML file) but also it requires overriding the entire .phtml file (not just the part you are changing) and it can lead to major problems down the road should there be updates to the file you're overriding (since your module has no way to detect those changes and overrides the entire file).
I just want to find a better way. Is there one?
EDIT:
Clarification: lets say I have a .phtml file with a single div. In that div there are appx. 210 lines of code (some are HTML lines, some are PHP lines). What I want to do is inject 160 new lines of code (some HTML, some PHP) prior to the existing lines that are inside that div, before it gets executed by the PHP interpreter.