Here is the code for anyone interested:
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> factoryMap = reg.getExtensionToFactoryMap();
factoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
ResourceSet resourceSet = new ResourceSetImpl();
EPackage PSM_Pkg = MyDSLPackage.eINSTANCE;
resourceSet.getPackageRegistry().put(PSM_Pkg.getNsURI(), PSM_Pkg);
Resource resource = resourceSet.getResource(Constants.PSM_URI, true);
EList<EObject> inObjects = resource.getContents();
// Xpand
URI outURI = URI.createURI("file:///C:/Users/...");
Output out = new OutputImpl();
Outlet outlet = new Outlet(outURI.toFileString());
out.addOutlet(outlet);
XpandExecutionContextImpl executionContext = new XpandExecutionContextImpl(out, null);
// Configure the metamodels
EmfMetaModel emfMetaModel = new EmfMetaModel();
emfMetaModel.setMetaModelPackage(MyDSLlPackage.class.getName());
executionContext.registerMetaModel(emfMetaModel);
XpandFacade xpandFacade = XpandFacade.create(executionContext);
Object[] params = null;
System.out.println(inObjects.get(0));
xpandFacade.evaluate("template::Template::main", inObjects.get(0), params);
System.out.println("Code generated.");