I should note that XPath is really the key here: it’s an elegant language to get and transform tree-structured and sequential data, so it could be well-used in a Pythonic template pipeline.
XSLT is a functional programming language that leans heavily on XPath to support transformation of tree-based structures. XQuery is another in the same vein. But you can accomplish the same things using an imperative language like Python, calling into XPath for data.