I’m transforming XML to XML and would like to indent the result automatically.
So I’m using <xsl:output method="xml" indent="yes"/>
When running this through .net4 compiled transform, it works well as long as there is no text node on the output.
Once I’m adding some text <xsl:text>some text</xsl:text> the indentation of the whole xml file is gone and the result XML consists of some very long lines instead (well formed but unreadable…)
Example:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<Root>
<!--xsl:text>some test</xsl:text-->
<Test1/>
<Test2/>
</Root>
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Test1 />
<Test2 />
</Root>
Result when removing the comment from <xsl:text>some test</xsl:text>:
<?xml version="1.0" encoding="utf-8"?>
<Root>some test<Test1 /><Test2 /></Root>
Any ideas?
Indenting specified with:
affects only the treatment of white-space-only nodes.
Whenever you specify non-whitespace-only text nodes, you must provide for them your own indenting — yourself.