d47cab
1,/
d47cab
d47cab
# on each new iso-code process the current one
d47cab
\!\(<iso_3166_entry\|</iso_3166_entries>\)!{
d47cab
    x
d47cab
    s/^$//
d47cab
    # we are on the first iso-code--nothing to process here
d47cab
    t
d47cab
    # process and write to output
d47cab
    s/\s\+/ /g
d47cab
    s/
d47cab
    s!/\s*>!!
d47cab
    # use '%' as a separator of parsed and unparsed input
d47cab
    s/\(.*\)alpha_2_code="\([^"]\+\)"\(.*\)/\2 % \1 \3/
d47cab
    s/\([^%]\+\)%\(.*\)alpha_3_code="\([^"]\+\)"\(.*\)/\1% \2 \4/
d47cab
    #  clear subst. memory for the next t
d47cab
    t clear
d47cab
    :clear
d47cab
    s/\([^%]\+\)%\(.*\)numeric_code="\([^"]\+\)"\(.*\)/\1% \2 \4/
d47cab
    t name
d47cab
    # no 3166 code--write xx
d47cab
    s/%/\tXX %/
d47cab
    :name
d47cab
    s/\([^%]\+\)%\(.*\)name="\([^"]\+\)"\(.*\)/\1\t\3/
d47cab
    s/ \t/\t/g
d47cab
    p
d47cab
    b
d47cab
    :noout
d47cab
}
d47cab
d47cab
H