This template seems to do what you want and will be faster because only one line of one switch_if() is executed. It works by concatenating generated URLs in the order according to the publisher. If the publisher isn't one of interest then it generates 'a03' first. Missing identifiers are ignored.
Another important point: list_join() strips out empty list values, so there isn't a problem with build_url() generating a trailing comma.
Code:
program:
def build_url(id):
return identifier_in_list($identifiers, id,
urls_from_identifiers(id & ':' & select($identifiers, id), 1) & ',', '')
fed;
list_join(
', ',
## trimmed out other lines for length
switch_if(
$publisher=='Archive of Our Own', build_url('ao3') & build_url('ffnet'),
$publisher=='FanFiction.net', build_url('ffnet') & build_url('ao3'),
build_url('ao3') & build_url('ffnet')
), ',',
)