PK.LABBKEY
A^prefix,
"PATS",@1,
END;

[1]::PATS
/ARGV[1]^DT,
2^nr,
DO{nr</ARGC 1,
   /ARGV[nr]^ACT,
   ?(A)AAAI[ACT]^aa,
   "BBK",@2,
   nr+1^nr};

[2]::BBK
""^Q,
DO{"NEXT.SPEC",@3 "SEND",@4};

[3]::NEXT.SPEC
>(?(SB)SBSP[aa,Q],sbs)^Q;

[4]::SEND
IF{$(SB)SBS[sms]|3<DT;
   "<Document>"^!,
   "<InstanceMnemonic>"_prefix_sbs_"</InstanceMnemonic>"^!,
   "append x to key because t0 may be empty",
   "<Key>"_"x"_$(SB)SBS[sbs]|23_"</Key>"^!,
   "<PersonMnemonic>"_:AA[aa]|3_"</PersonMnemonic>"^!,
   "<EventEndDateTime>"^!,
   IF{$(SB)SBS[sbs]|13_.'=. $(SB)SBS[sbs]|3_$(SB)SBS[sbs]|4;
      $(SB)SBS[sbs]|14_.'=. $(SB)SBS[sbs]|9_$(SB)SBS[sbs]|10}^!,
   "</EventEndDateTime>"^!,
   "<EventSetMnemonic>BBK</EventSetMnemonic>"^!,
   "</Document>"^!};
