libxslt does exactly what you want if you don't provide an indent attribute at all. indent="yes": Let libxslt add whitespace. indent="no": Never add whitespace. no indent attribute: Add newline after top-level nodes. Nick