I wouldn’t need a full-fledged document parser. I’m envisioning just a simple additive text function. Let’s say the topmost document (id=0) has a value in an inheritable TV, and its child document, and that child’s document. I would want them them each appended to the next. Here’s an example:
Document id=0
value of inheritable TV: "body {color:black;}"
Document id= 1 (child of document 0)
value of inheritable TV: "p {background:blue;color:white}"
cumulative value:
"body {color:black;}
p {background:blue;color:white}"
Document id=2 (child of document 1)
value of inheritable TV: "a {color:yellow}"
cumulative value:
"body {color:black;}
p {background:blue;color:white}
a {color:yellow}"
In programming terms, the final result would be reached by something as simple as:
$inheritableTvs = array(put values here);
$inheritableTvs = implode("\r\n", $inheritableTvs);
It’s just a matter of putting them one right after another, presumably with a line break in between them, or a space, but nothing more than that. Of course, to arrive at that last bit of code would require walking through the hierarchy back to the topmost parent. There would be some overhead involved in that. One way to deal with that would be to require the word "@INHERIT" at the beginning of the value of the TV as a flag to continue walking through the hierarchy. So the value for document 1 would be:
@INHERIT
p {background:blue;color:white}
The value for document 2 would be:
@INHERIT
a {color:yellow}
If you want to stop the inheritance, you could omit the "@INHERIT", and that would be the flag to stop there.