Generating quark and gluon fragmentation functions from QCD