beMe Posted March 13, 2011 Share Posted March 13, 2011 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 More sharing options...
boen_robot Posted March 13, 2011 Share Posted March 13, 2011 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 More sharing options...
beMe Posted March 13, 2011 Author Share Posted March 13, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.