I'm required to do a transformation around patient physical addresses. If (for whatever reason) a patient has multiple addresses, I want to move the home address to the first iteration of PID:11 and remove all other iterations. I've accomplished the first bit using DTL, but for patients who have multiple addresses they are left with empty trailing iterations. Here is an example I mocked up:

How can I remove those trailing iterations?
This is part of the DTL I've written to do my transformation:
<foreach property='target.{PID:PatientAddress()}' key='i' >
<if condition='source.{PID:Patien
.png)