Blank rows in Doc Merge PDF template

We have a template that used this logic successfully within wDocs. Nevertheless, during the transition to Doc merge, it now fills in all the product lines on the quote. I've wrote a new simple code that only populates the products if they meet specific criteria; however, I'm encountering persistent blank rows that have proven quite challenging to eliminate.
Any suggestions on how to eliminate the blank rows would be greatly appreciated!
Thanks in advance
Christopher

{#products filter='Accessories'}{product_template_name.name capitalize='true'}  {category_name} {/products}

Fig 1: WDocs code

{#products sort='cattest_c:desc'}
{if cattest_c=='Accessories'} {product_template_name.name}
{elseif cattest_c!='Accessories'}
{endif}
{/products}

Fig 2:Doc merge new code

Fig 3: Doc merge PDF