Jump to content

sort xml data


beMe

Recommended Posts

Hi,I have an xml tat looks like this:<users> <id>45</id> <id>31</id> <id>40</id></users>i need the same xml, but with sorted ids:<users> <id>31</id> <id>40</id> <id>45</id></users>i tried all kinds of <xsl:sort>but - or they do not work or, they return the first one only.how can i do it? (I prefer xslt)thanks!!!

Link to comment
Share on other sites

There are a few ways, but the most direct is probably

<xsl:template match="/users">	<users>		<xsl:for-each select="id">			<xsl:sort select="." data-type="number" />			<id><xsl:value-of select="." /></id>		</xsl:for-each>	</users></xsl:template>

The idea is to loop over each element, and sort by its contents casted to a number.

Link to comment
Share on other sites

There are a few ways, but the most direct is probably
<xsl:template match="/users">	<users>		<xsl:for-each select="id">			<xsl:sort select="." data-type="number" />			<id><xsl:value-of select="." /></id>		</xsl:for-each>	</users></xsl:template>

The idea is to loop over each element, and sort by its contents casted to a number.

Thank u for the fast replay!!it helped!!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...