How do I make xsl transformation indent the output?
For indentation you need to use a different namespace: http://xml.apache.org/xslt
(see this issue)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
extension-element-prefixes="redirect"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" indent="yes" xalan:indent-amount="4"/>
Was struggling with this for a while, however just got it working accidentally:
the key was to add <xsl:strip-space elements="*"/>
so it will look like this:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xalan/java"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" encoding="ASCII" indent="yes" xalan:indent-amount="4"/>
<xsl:strip-space elements="*"/>
Not sure why, but probably removing all whitespacing helps xalan figure out the indentation
Jirka-x1, thank you for the issue-link. I used the following (as proposed by Ed Knoll 13/Aug/04):
<xsl:stylesheet ... xmlns:xslt="http://xml.apache.org/xslt">
<xsl:output ... indent="yes" xslt:indent-amount="4" />
This works for me with xalan (java) 2.7.1.