tp-20,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
table table:nth-child(2n + 1){
border : #FF0000 3px solid;
}
table table:nth-child(2n){
border : #0000FF 3px solid;
}
table table{
width: 100%;
margin: 1px;
}
</style>
</head>
<body>
<table>
<tr>
<td>Маша</td>
<td>Карандаш</td>
<td>1</td>
</tr>
<tr>
<td></td>
<td>Ручка</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td>Блокнот</td>
<td>4</td>
</tr>
<tr>
<td></td>
<td>Прищепка</td>
<td>4</td>
</tr>
<tr>
<td>Саша</td>
<td>Шышка</td>
<td>5</td>
</tr>
<tr>
<td></td>
<td>Мышка</td>
<td>1</td>
</tr>
<tr>
<td></td>
<td>Батарейка</td>
<td>6</td>
</tr>
<tr>
<td>Коля</td>
<td>Баян</td>
<td>2</td>
</tr>
<tr>
<td></td>
<td>Гармонь</td>
<td>1</td>
</tr>
<tr>
<td></td>
<td>Балалайка</td>
<td>2</td>
</tr>
<tr>
<td></td>
<td>Гитара</td>
<td>1</td>
</tr>
<tr>
<td>Валя</td>
<td>Скотч</td>
<td>2</td>
</tr>
<tr>
<td></td>
<td>Флешка</td>
<td>1</td>
</tr>
<tr>
<td>Ира</td>
<td>Спички</td>
<td>3</td>
</tr>
<tr>
<td></td>
<td>Бычки</td>
<td>9</td>
</tr>
<tr>
<td></td>
<td>Штучки</td>
<td>5</td>
</tr>
</table>
<script>
let table;
document.querySelectorAll("tr").forEach(tr => {
const name = tr.querySelector("td").textContent.trim();
if(name) {
table = document.createElement("table");
tr.parentNode.replaceChild(table, tr)
}
if(table) table.append(tr)
})
</script>
</body>
</html>