[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Group and sort by group element occurrences


Subject: RE: [xsl] Group and sort by group element occurrences
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 19 Aug 2003 08:19:42 +0300

Hi,

> I need to transform this this into a grouped and sorted list of page
> id's, so that the instances of pageid that occur the most 
> frequently are
> first, and so that each pageid is listed only once. The above 
> xml would
> then look like this.
> 
> <docroot>
> 	<pageid>84</pageid>
> 	<pageid>3</pageid>
> 	<pageid>5</pageid>
> 	<pageid>1</pageid>
> </docroot>

  <xsl:key name="id" match="pageid" use="."/>
  <xsl:template match="docroot">
    <xsl:copy>
      <xsl:for-each select="token/pageid[generate-id(.) = generate-id(key('id', .))]">
        <xsl:sort select="count(key('id', .))" data-type="number" order="descending"/>
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

Cheers,

Jarno - Delerium: After All

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml