I have the following simplified XML:
<Data>
<DataValue>Data</DataValue>
<Product>
<Price>60</Price>
<Value>Product Value</Value>
</Product>
<Product>
<Price>50</Price>
<Value>Product Value</Value>
</Product>
<Information>
<Entry>Some Information Text</Entry>
</Information>
<Description>
<Entry>Some Description Text</Entry>
</Description>
</Data>
I sort the product elements by the price value, with the following xslt code:
<xsl:template match="@*">
<xsl:attribute name="{name()}"><xsl:value-of select="normalize-space(.)"/></xsl:attribute>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="*[local-name()='Data']">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="*[not(local-name()='Product')]"/>
<xsl:apply-templates select="*[local-name()='Product']" >
<xsl:sort data-type="number" select="*[local-name()='Price']/text()" order="ascending"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
Which leads to the following wrong result:
<Data>
<DataValue>Data</DataValue>
<Information>
<Entry>Some Information Text</Entry>
</Information>
<Description>
<Entry>Some Description Text</Entry>
</Description>
<Product>
<Price>50</Price>
<Value>Product Value</Value>
</Product>
<Product>
<Price>60</Price>
<Value>Product Value</Value>
</Product>
</Data>
The problem now is that the correctly sorted "Products" elements are placed at the end after the transformation. Is there a way to sort only parts of an xml while the other elements remain untouched and also remain on the same places?