XML reindent: a poor-man's Tidy

/xml/stylesheets/reindent/

File Name  ↓ File Size  ↓ Date  ↓ 
--
-2015-Oct-24 20:47
5012006-Oct-26 02:51
25922015-Oct-24 20:46

Description: Some producers of XML do a poor job of indenting. For example, as of 2006, Xalan and MSXML are very conservative about how much whitespace they put into serialized XSLT results when xsl:output indent="yes".

The reindent.xsl stylesheet demonstrates how you can use XSLT to properly indent XML, without relying on the processor's built-in indenting capability. This is useful if you are starting with poorly indented XML and want to produce nicely indented XML.

If you instead apply the reindent-html.xsl stylesheet, the output will be HTML with similarly cleaned-up indenting. This is useful if you are starting with poorly indented XHTML and want to produce nicely indented HTML.

Requirements: Any XSLT 1.0 or 2.0 processor should be able to handle this.

See also: other reindenting methods in the XSLT FAQ. (Mine is better than any of them, as far as I can tell).