Natural order - xsl:sort Options
tim
Posted: Friday, December 14, 2007 12:31:22 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Hey,

I Have the following problem. On my documentype i have a property 'views', this is a numeric datatype.

So I want to list al the nodes of my documenttype and sort them according to the value in 'views'.

Code:

<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias = 'GalleryPage']/descendant-or-self::node [@nodeTypeAlias = 'Movie']">
<xsl:sort select="data [@alias = 'views']" order="descending"/>
<xsl:if test="position() &lt;= $numberOfItems">
<xsl:call-template name="listMovies">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>



But the problem is that the items are not in natural order.

For example:
86
8
14
12
0

I think that is because the data [@alias = 'views'] is seen as a String. How can i change this ?

Thanks



Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Friday, December 14, 2007 12:32:58 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Nevermind, found the solution:

Code:

<xsl:sort select="data [@alias = 'views']" order="descending" data-type="number"/>


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.