Possible Issue with HTML::TreeBuilder?
am 05.07.2005 15:49:19 von admiral.grinderI am having a problem deleting a temporary attribute from a HTML node.
The XML spec that I am using allows a user to declare a table similar
to HTML. Inside this table there are 'tgroups' which allows a author
mix several tables into one table. An example is a table that has 3
tgroups with the first and last being 2 columns and the second (middle)
one being 3 columns. The trick is doing this on the fly and making it
look good.
I have an algorithm that will do all the column spanning calculations
so it all appears correctly. The 'tgroup' has a attribute that
declares how many columns that part of the table has. Using that
information I was able to have my XSLT pass it on as an attribute to a
html 'tbody' or 'thead' tag. Perl then uses those attributes with the
algorithm and distrubutes colspan to the table elements making it look
good. Since HTML 'tbody' or 'thead' doesn't allow it to have the
attribute I gave it I need to remove these attributes before it goes to
the web browswer (I am using XHTML as output).
The problem lies when I try to remove the attribute. Whether I try to
remove it right after I retrieve it for a particular block or after I
am done with that block altogether it causes all the calculations to
foul up causing my tables to look crappy. I am using it like such:
# for each table
# Collect tbody elements
my @tbodies = $table->look_down(_tag => 'tbody') ;
# calculate magic number
# process table blocks
foreach my $table_block (@tbodies) {
# find out how many columns each cell will span
my $col_span = $magic_number / $table_block->attr('num_cols') ;
# Apply the col_span to the cells in this block.
# deleting attrib. it is non standard and only used for us to
transform
$table_block->attr('num_cols', undef);
}
If I do not try to delete the attribute then all is happy, but when I
delete the attribute all my calculations end up giving me a col_span =
0 for all tables in the page where this applies.
Has anybody else had this problem and any work arounds? I am running
this program on a hyper threaded processor and I wondering if I am
having thread issues, or a timing issue between that module and the
rest of my code? The only work around I can come up with at the moment
is to either don't delete the attribute (but it would be better if I
did), or to dump the HTML tree into another HTML::TreeBuilder object
and then delete them there (time comsuming and the target platform is a
200 mhz machine running other programs)