Applications of Fold to XML Transformation

Andy Wingo · 2007

The benefit of considering XML parsing as a fold operation over the tree of elements is perhaps the best-kept secret in XML. Applying common functional programming patterns to the XML problem domain yields parsers that are both more expressive and less prone to common bugs. This paper investigates the usefulness of fold as not just a pattern for parsing, but for transformation of parsed XML as well. A new variant of fold is introduced that is shown to underly the existing patterns of transforming XML, while providing functionality heretofore possible only via second-order traversal. Real-world examples are explored, including the motivating problem for this investigation: layout of declarative documents into Scalable Vector Graphics (SVG). 1.

Read the paper · More papers on PaperTik