You can do the borders purely in CSS with no HTML changes needed.
Demo Fiddle
Try this CSS:
table {
border: 1px solid black;
border-collapse: collapse;
}
td, th {
border:1px solid black;
}
tr th:not([rowspan]){
border-top:none;
border-bottom:none;
}
For the line separation, you can either play with the widths or use JohnBupits answer above.