I'm trying to figure out how to preserve the whitespace nodes between the nodes I'm sorting. Here is an example.
Input:
<a>
<b>
<c>
<d>world</d>
</c>
<c>
<d>hello</d>
</c>
</b>
<e>some other stuff</e>
</a>
Desired output:
<a>
<b>
<c>
<d>hello</d>
</c>
<c>
<d>world</d>
</c>
</b>
<e>some other stuff</e>
</a>
Here is my xslt:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a/b">
<xsl:copy>
<xsl:apply-templates select="c">
<xsl:sort select="d"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And when I run it through xsltproc, I get this:
<a>
<b><c>
<d>hello</d>
</c><c>
<d>world</d>
</c></b>
<e>some other stuff</e>
</a>
I'd rather not run it through tidy afterward. Ideas?