I have an XML file whose contents I want to sort by document order (basically in the order that the items were written out).
I currently use the following code:
<xsl:template match="/Error">
<xsl:apply-templates>
<xsl:sort select="position()" order="descending" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="/Error/Warning">
<!-- etc -->
</xsl:template>
Example XML (data replaced for ease of reading):
<Error>
<Warning data="stuff" timestamp="08:26:17 2010/08/01">CODE.1</Warning>
<Clear data="stuff" timestamp="08:26:36 2010/08/01">CODE.2</Clear>
<Warning data="stuff" timestamp="08:36:00 2010/08/01">CODE.3</Warning>
<Clear data="stuff" timestamp="08:36:56 2010/08/01">CODE.4</Clear>
<Warning data="stuff" timestamp="08:40:31 2010/08/01">CODE.5</Warning>
</Error>
This, however, seems to give odd results as it seems to be in no particular order! Any ideas?
Removing the sort seems to make it work properly - will this reliably order it in write-order or is that not guaranteed?