View Single Post
  #1 (permalink)  
Old August 12th, 2005, 01:41 AM
BeneathClouds BeneathClouds is offline
Registered User
 
Join Date: Aug 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting & Limiting a for-each (top most recent)

Hello,

What I am effectively trying to achieve is sorting a group of elements, then from this sorted grouping return the top 5 elements.

Cut down version of the XML is:

Code:
<customfield name="WhatsNew">
    <pages>
        <listitem>
              <title>Wrox books are cool</title> 
              <url>/theforums/aregreat/</url> 
            <doc-dates>
                <published-date>2005-07-29T15:02:52.9800000+10:00</published-date> 
            </doc-dates>
        </listitem>
        <listitem>
              <title>Wrox books are cool</title> 
              <url>/theforums/aregreat/</url> 
            <doc-dates>
                <published-date>2005-08-29T15:02:52.9800000+10:00</published-date> 
            </doc-dates>
        </listitem>
    </pages>
    <sections>
        <listitem>
              <title>Wrox books are cool</title> 
              <url>/theforums/aregreat/</url> 
            <doc-dates>
                <published-date>2005-03-29T15:02:52.9800000+10:00</published-date> 
            </doc-dates>
        </listitem>
    </sections>
<customfield>
A cut down version of what I was trying was:

Code:
<xsl:for-each select="//customfield[@name='WhatsNew']/node()/listitem">
    <xsl:sort select="doc-dates/published-date" order="descending" />
    <xsl:if test="position() &lt; 6">
        <xsl:variable name="day" select="substring(doc-dates/published-date,9,2)" />

        <a>
            <xsl:attribute name="href">
                <xsl:value-of select="url"/>
            </xsl:attribute>
            <xsl:value-of select="title"/> 
        </a> - <xsl:value-of select="$day"/>
    </xsl:if>
</xsl:for-each>
Now from what I can tell "position()" only refers the the position of the element within the XML not within the 'sorted' version of it.

Any suggestions would be much appreciated!!!!

Reply With Quote