This sounds neat! It looks like this creates a sitemap "route" though... If that is the case, I think this could be more useful as a command-line script that generates a static .xml file (which could then be served as a static resource).
I've done a lot of search optimization for large sites, and the biggest source of issues has always been with dynamic sitemaps (many random reasons). Being able to have a static one, which can also be tracked in version control, has avoided almost every problem I've encountered.