Often it is simplest to use Unix scripts or Perl (Python), esp. on normalised instances of SGML documents.
A freely available SGML processing engine is Omnimark Light (Omle). A snippet from an Omnimark program:
;
; Handle Images...
;
ELEMENT IMG
OUTPUT "<%q "
DO WHEN ATTRIBUTE src IS SPECIFIED
OUTPUT " src=%"%v(src)%" "
DONE
DO WHEN ATTRIBUTE align IS SPECIFIED
OUTPUT " align=%"%v(align)%" "
DONE
DO WHEN ATTRIBUTE ismap IS SPECIFIED
OUTPUT " ISMAP"
DONE
OUTPUT ">%sc"