xsl-list
[Top] [All Lists]

RE: Sorting XML and select top 10

2005-01-12 15:18:25
You might try using selection to collect top ten and sort ...

Something like this might work:
    <xsl:template match="/">
        <xsl:apply-templates select="/onderwerpen[position()<11]">
                <xsl:sort select="@datum"/>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="onderwerpen">
        <!-- do stuff for each onderwerpen -->
    </xsl:template>

I'm not sure if the sort happens before or after the selection. You may
need to do this in two passes.

Hope that helps.

Douglas Ross
Developer, HTML UI Framework
Kronos
www.kronos.com

-----Original Message-----
From: gerritjan [mailto:gerritjankoekkoek(_at_)mac(_dot_)com] 
Sent: Wednesday, January 12, 2005 3:09 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Sorting XML and select top 10

I would like to sort an XML source. Then select the first 10 of the 
sorted list being the 10 newest articles
I've come up with this XSLT so far, but it does not work (it sorts on 
'onderwerp', the subject of the for-each)
<xsl:template match="onderwerpen" >
       <xsl:variable name="teller">0</xsl:variable>
     <xsl:for-each select="onderwerp">
        <xsl:sort select="onderwerp/@datum" order="descending"/>
        <xsl:if test="$teller &lt;= 10">
            <xsl:variable name="teller"><xsl:value-of 
select="$teller+1"/></xsl:variable>
               <item>
                         <title>
                <xsl:value-of select="@titel"/>         
                         </title>
                         <link>
                <xsl:value-of select="@menu"/>
                <xsl:text>_</xsl:text>
                <xsl:value-of select="@beveiliging"/>
                <xsl:text>_</xsl:text>
                <xsl:value-of select="@bestand"/>
                <xsl:text>.html</xsl:text>
                         </link>
             <xsl:apply-templates select="inleidingtekst"/>
             <pubDate>
                <xsl:value-of select="@datum"/>
             </pubDate>
                   </item>
                </xsl:if>
     </xsl:for-each>
   </xsl:template>

Anybody having suggestions how to do this?

Gerritjan Koekkoek


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>