XSLT is a declarative domain-specific language for transforming and manipulating trees and forests. Its more powerful than you might expect, and these days can read and write EPUB files.
Using fn:transform(), file:write(), archive:zip() and more.
Contact liam at fromoldbooks.org for more information.