IN: ref-template USING: kernel xml sequences hashtables tools io arrays namespaces generic ; SYMBOL: ref-table : replace-ref ( ref -- object ) reference-name ref-table get hash call ; : r-ref-string ( xml-string -- xml-string ) xml-string-array [ dup reference? [ replace-ref ] when ] map ; GENERIC: (r-ref) ( xml -- object ) M: any-tag (r-ref) dup tag-props dup [ dup [ r-ref-string swap set ] hash-each ] bind over set-tag-props ; M: reference (r-ref) replace-ref ; M: object (r-ref) ; : replace-refs ( xml -- xml ) [ (r-ref) ] xml-map ; ! Example : test-refs H{ { "foo" [ "foo" ] } { "bar" [ [ .s ] string-out ] } { "baz" [ "" string>xml delegate ] } } ref-table set "%foo;%bar;%baz;" string>xml replace-refs ;