Output rules within an @if in the correct order (#12438)

Change-Id: Id30722a25cedb4c87c8ddab614b82355c1bbd96e