One
thing XMLC does very poorly is allow you to remove elements from one template
row in a table, but have them re-appear in subsequent template rows.
The
common case for this is when you have an HREF in your template row that you
wish to disable for certain rows -- you must remove the HREF element to do
this. The simplest options for
doing this all have drawbacks:
1.
clone the template node first, then remove unneeded
elements from it. This loses the
most convenient XMLC feature, namely the ability to reference tags via page.getElementFoo() methods. No
such methods exist on the template row object (imho
this would be the most powerful feature to generate class files for specific
template rows).
This
is why I think everyone modifies the template row, THEN
clones the modified version. Note
this is very suboptimal for cases when you have a nested table associated with
the first template row, but I'll leave that discussion for another day)
2.
Remove the elements from the template row, clone the row, and then insert the
elements back when needed.
Drawbacks: hard to know
where exactly to insert these elements (generally this requires MORE id=
attributes added to the HTML to serve as a placeholder). Also this is very hard to generalize:
whether or not to insert these items back (or remove them) depends on whether
you removed them/ re-inserted the elements previously. You could always put them back when you
remove them, but this is inefficient in cases where you have N adjacent rows,
all of which need the element removed.
I've
settled on a third approach, which seems to be working well, and I'd like to
hear comments about:
3.
I process the template row using the page.getElementXX() methods, then clone it. If I want to remove an element, I do not
remove it, but rather assign a special value ('deleteme')
to the elements name= attribute.
I
use a table to associate all items I've 'marked' in this way with the template
row object that I am about to clone. I created a function that will clone the
passed-in template row, and go thru the table 'resetting' the name attribute
for all the nodes I had used previously. Then, before rendering the page, I go
thru the page and getElementsByName('deleteme') and remove them.
This
two-step mark & delete approach seems to work well. Of course it clobbers
the 'name' attributes in the process, but so far I haven’t needed those
on the elements I am deleting in this fashion.
I'd
be curious to hear what others think of this approach.
--
David Michaels, Director of Web Engineering
PGP Corporation (650) 319-9009