First of all, that can't be your actual HTML, surely? There's no such thing as a <rowspan>tag. More to the point, I'm not sure if it's possible to figure out what was the intention from the HTML you've given us. There's more than one possible correct answer to the problem as far as I can see. Is each of those blocks of code a table row? It doesn't make sense. Tell us the big picture, please. What are you trying to do, where does the code come from, etc.